help-octave
[Top][All Lists]
Advanced

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

Re: newbie question: assigment to N-d arrays returns strange values


From: Henry F. Mollet
Subject: Re: newbie question: assigment to N-d arrays returns strange values
Date: Sat, 06 Aug 2005 11:55:14 -0700
User-agent: Microsoft-Entourage/11.1.0.040913

If m=zeros(3, 2, 2);
Then what does m(3,:) mean?
I understand m(3,:,:):
octave:14> m(3,:,:)
ans =
ans(:,:,1) =
  0  0
ans(:,:,2) =
  0  0
Henry


on 8/5/05 11:31 PM, Amir Seginer at address@hidden wrote:

> Hello,
> 
> This might be a known problem, but I couldn't find any reference to it.
> When assigning to an n-dimensional array (see below) I get results which
> are different from Matlab. Also, in one case I get some strange values
> in the array as well.
> 
> I wrote the the following code in Octave (using --traditional):
> 
>>>  m=zeros(3, 2, 2) ;
>>>  a= [1 2 3 4] ;
>>> m(3, :) = a
> m =
> 
> ans(:,:,1) =
> 
>          0        0
>          0        0
>          1        2
> 
> ans(:,:,2) =
> 
>          0        0
>          0        0
>          0        0
> 
> which is not what I expected (3 and 4 were not assigned). Even worse,
> when I did
> 
>>> m=zeros(3, 2, 2) ;
>>> a= [ 1; 2; 3; 4] ;
>>> m(3, :) = a
> m =
> 
> ans(:,:,1) =
> 
>          0        0
>          0        0
>          1        2
> 
> ans(:,:,2) =
> 
>    0.0e+00  *
> 
>        NaN      NaN
>        NaN      Inf
>        NaN      Inf
> 
> This gives strange values on the 2nd "page". Further more, in normal
> mode the same code gave
> 
> octave:8> m=zeros(3, 2, 2) ;
> octave:9> a= [ 1; 2; 3; 4] ;
> octave:10> m(3, :) = a
> m =
> 
> ans(:,:,1) =
> 
>    0  0
>    0  0
>    1  2
> 
> ans(:,:,2) =
> 
>      0.0000e+00   5.1715e-319
>     1.1116e-321    0.0000e+00
>      0.0000e+00    0.0000e+00
> 
> Is there a way to overcome this, or at least get an error/warning. I'm
> using octave-2.1.71
> 
> Thanks,
> 
> Amir.
> 
> 
> 
> -------------------------------------------------------------
> 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
> -------------------------------------------------------------
> 




-------------------------------------------------------------
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]