MatLab Size command

  • MATLAB
  • Thread starter robax25
  • Start date
  • #1
182
2

Main Question or Discussion Point

I have a little bit confusion that how size command work.can body explain please?. For Example
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?
 

Answers and Replies

  • #2
1,428
1,253
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):
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:
  • Like
Likes RPinPA and jedishrfu

Related Threads on MatLab Size command

Replies
4
Views
13K
  • Last Post
Replies
11
Views
1K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
4
Views
24K
Replies
4
Views
775
  • Last Post
Replies
1
Views
2K
Replies
2
Views
5K
Replies
5
Views
693
Replies
1
Views
478
Replies
0
Views
3K
Top