
From:  Amir Seginer 
Subject:  Re: newbie question: assigment to Nd arrays returns strange values 
Date:  Sat, 06 Aug 2005 22:55:44 +0300 
Useragent:  Mozilla Thunderbird 1.0.61.1.fc4 (X11/20050720) 
Henry F. Mollet wrote:
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
Well, on Matlab, as well as on octave, m(3,:) means a row vector which represents the 2x2 matrix m(3,:,:).
For example, this works on both Ocatve and Matlab >> m=zeros(3, 2, 2) ; >> m(3,1,2)=1; >> m(3,1,1)=1; >> m(3,2,1)=2; >> m(3,1,2)=3; >> m(3,2,2)=4; >> m m = ans(:,:,1) = 0 0 0 0 1 2 ans(:,:,2) = 0 0 0 0 3 4 >> m(3,:) ans = 1 2 3 4 Since this does work on Octave, I was expecting the assigment m(3,:) = [1 2 3 4] to also work (as it does on Matlab). Thanks, Amir.
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 ndimensional 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, :) = am = 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 didm=zeros(3, 2, 2) ; a= [ 1; 2; 3; 4] ; m(3, :) = am = 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.1715e319 1.1116e321 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 octave2.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 
[Prev in Thread]  Current Thread  [Next in Thread] 