what's the second variable in size function do ?
조회 수: 7 (최근 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
댓글 수: 0
채택된 답변
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
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
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 Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!