what's the second variable in size function do ?

29 次查看(过去 30 天)
Hi,
I am little confused about the size function. please see the attached. for example,
let's say f= [ 4 3 5 6 ]
now if I write size(f,1) I get f = 1
if I write size (f,2) I get f = 4
if I write size (f,3) I get f = 1
if I write size ( f,4) I get f = 1
My question what does the number 1,2,3,4 mean/do in the size function mentioned above ? Thanks

采纳的回答

James Tursa
James Tursa 2018-1-5
The second argument to the size function designates the particular dimension that you want. E.g., in your example, f is a 1x4. The first dimension is 1, the second dimension is 4. That is why size(f,1) returns 1 and size(f,2) returns 4. For the trailing dimensions that are not physically present in a variable, size returns 1 by convention. So size(f,3) returns 1, size(f,4) returns 1, and size(f,20) would return 1 also.
  5 个评论

请先登录,再进行评论。

更多回答(1 个)

faw3b
faw3b 2018-1-5
The function returns the length of the specified dimension (Take a look at the function Documentation). The array f is an 1x4 array. So its first dimension is 1, the second 4.
If you define another array with different dimensions (2x3 array)
A = [5 7 8;
0 1 9];
the function returns
size(A,1)
ans =
2
and
size(A,2)
ans =
3
the array dimensions. A two dimensional array with three elements each.
  2 个评论
Anthony Santana
Anthony Santana 2021-11-15
I have a followup. What does this mean?
eta = (X' - repmat(constant,size(X,1),1)' where:
X' = (652X3)' or (3X652), X = (652X3), constant = [1X3], lets say it contains [5 2 1].
I assume size (X,1) is first dim of X or '652'.
Then this eta = 3X652 - repmat [(1X3),652,1)]' ?'
Q1 The second part is a [(1X3) with 652 rows and 1 column] transposed?
Let's say it's like:
[5 2 1]
[5 2 1]
...
[5 2 1] (652th row)?
Q2. Then its transpose is:
[5 2 1] [5 2 1] ... [5 2 1} for 652 columns?
Q2 How is this possibly subtracted from X' = [652X3]?
Q3 Or is the transpose somehow:
[5
2 for 652 columns, so it's 3 X 652 as well?
1]
-----
3D arrays a bit confusing. Thanks in advance.
T

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by