help-octave
[Top][All Lists]
Advanced

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

Re: Array of variable dimension


From: John W. Eaton
Subject: Re: Array of variable dimension
Date: Fri, 11 Feb 2005 13:10:33 -0500

On 11-Feb-2005, Andrey Romanenko <address@hidden> wrote:

| On Friday 11 February 2005 16:54, Deepak, R. wrote:
| > How can I create an 'y'-dimensional array of zeros, where each dimension
| > can take (2 * n + 2) values?
| >
| > 'y' and 'n' are variables given at runtime.
| 
| Like this?
| 
| 
| y=3;
| n=2;
| 
| nn=2*n+2;
| 
| ss=sprintf("zz=zeros(%d",nn);
| for i=2:y
|  ss=strcat(ss, sprintf(",%d", nn));
| endfor;
| ss=strcat(ss, ");");
| 
| eval(ss)
| 
| zz

Or perhaps something a bit simpler:

  dims = repmat (2*n+2, 1, y)
  zeros (dims)

jwe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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