what's the second variable in size function do ?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Akim Mahmud
am 5 Jan. 2018
Kommentiert: Anthony Santana
am 15 Nov. 2021
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 Kommentare
Akzeptierte Antwort
James Tursa
am 5 Jan. 2018
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 Kommentare
Weitere Antworten (1)
faw3b
am 5 Jan. 2018
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 Kommentare
Anthony Santana
am 15 Nov. 2021
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
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!