[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

4-D Array

From: John W. Eaton
Subject: 4-D Array
Date: Thu, 10 Sep 2009 13:09:21 -0400

On 10-Sep-2009, Carlo de Falco wrote:

| I am trying to create a 4D NDArray (3x3x3x3) from within
| an oct-file but I don't understand how dim_vector works,
| I tried the following but it crashes Octave:
|    dim_vector a (4);

Looking at the dim-vector.h header file, I see

  explicit dim_vector (octave_idx_type n)
    : rep (newrep (2))
      rep[0] = n;
      rep[1] = 1;

so dim_vector a(4) creates a dimension vector for an 4x1 object.  You
need to do

  dim_vector a;
  a.resize (4);
  a(0) = 3;
  a(1) = 3;
  a(2) = 3;
  a(3) = 3;

or, since your dimensions are all the same, this should also work:

  dim_vector a;
  a.resize (4, 3);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]