- #1

- 220

- 3

A=[1 2 3;4 5 6;7 8 9];

size(A)

=3 *3

but size(A,1)=3 and size(A,2)=3 and size(A,3)=1 why is size(A,3)=1?

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- MATLAB
- Thread starter robax25
- Start date

- #1

- 220

- 3

A=[1 2 3;4 5 6;7 8 9];

size(A)

=3 *3

but size(A,1)=3 and size(A,2)=3 and size(A,3)=1 why is size(A,3)=1?

- #2

- 1,740

- 1,572

When you are doing ##size(A, 1)## or ##size(A, 2)##, 1 and 2 are **dimensions** here, not the row or column. Since the array is 3×3 (a two-dimensional matrix), the 1st dimension is 3, and the second is 3.

If you create a 3×3×3 matrix (a three-dimensional matrix), the 3rd dimension would be 3, but any higher order dimensions would be 1.

As a basic rule, if an array ##A## is n-dimensional, then ##size(A, dim)## returns the size of that**dimension**. If ##dim## exceeds ##n##, then 1 is returned.

Since you've created a two-dimensional array, all command that use dimensions > 2 return 1.

Try this and let me know whether you understand the output (don't copy and paste, as that often generates wrong outputs):

Read more here.

Edit: Grammar and formatting.

If you create a 3×3×3 matrix (a three-dimensional matrix), the 3rd dimension would be 3, but any higher order dimensions would be 1.

As a basic rule, if an array ##A## is n-dimensional, then ##size(A, dim)## returns the size of that

Since you've created a two-dimensional array, all command that use dimensions > 2 return 1.

Try this and let me know whether you understand the output (don't copy and paste, as that often generates wrong outputs):

Matlab:

```
A = ones(2, 3, 4);
[sz1 sz2 sz3] = size(A)
[sz1 sz2 sz3 sz4 sz5] = size(A)
```

Read more here.

Edit: Grammar and formatting.

Last edited:

Share: