what's the second variable in size function do ?
29 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Akim Mahmud
il 5 Gen 2018
Commentato: Anthony Santana
il 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 Commenti
Risposta accettata
James Tursa
il 5 Gen 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 Commenti
Più risposte (1)
faw3b
il 5 Gen 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 Commenti
Anthony Santana
il 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
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!