[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: size and display of N-d matrices (octave-3.4.2)
From: |
Ben Abbott |
Subject: |
Re: size and display of N-d matrices (octave-3.4.2) |
Date: |
Wed, 10 Aug 2011 17:20:09 -0400 |
On Aug 10, 2011, at 3:26 PM, Sergei Steshenko wrote:
> Hello,
>
> here is a screen session:
>
> "
> octave:1> a(1,1,1,1) = 1
> a = 1
> octave:2> a(1,1,1,2) = 2
> a =
>
> ans(:,:,1,1) = 1
> ans(:,:,1,2) = 2
>
> octave:3> a
> a =
>
> ans(:,:,1,1) = 1
> ans(:,:,1,2) = 2
>
> octave:4> size(a)
> ans =
>
> 1 1 1 2
>
> octave:5> b(1,1,1,1) = 3
> b = 3
> octave:6> b(2,1,1,1) = 4
> b =
>
> 3
> 4
>
> octave:7> b
> b =
>
> 3
> 4
>
> octave:8> size(b)
> ans =
>
> 2 1
>
> octave:9>
> ".
>
> Questions:
>
> 1) why does 'octave' treat 'a' and 'b' differently ?
For "b" the 3rd and 4th indices do not effect how the data is stored in memory.
Thus, they are superfluous and are pruned just as they are in Matlab.
> 2) why 'b' is shown to have just two dimensions ?
Because only two dimensions are needed to access the data.
a = 1:5;
a(1,5,1,1,1,1,1,1,1)
ans = 5
> 3) why colons when 'a' is displayed ?
It isn't clear in the context of your example, but if you try something a bit
more complex, you'll see that 2D arrays are displayed one at a time.
rand(3,2,3)
ans(:,:,1) =
0.876498771074170 0.228249951644748
0.838197338433857 0.112306693206123
0.881025682532475 0.835890938593277
ans(:,:,2) =
0.359380637345459 0.930091325028269
0.531543061712508 0.041806801803684
0.327139516557781 0.199321073527378
ans(:,:,3) =
0.294857085276711 0.719111880031177
0.602939270626089 0.753767065450199
0.633018499368617 0.063436978647205
Ben