M = reshape(linspace(11,18,8),[2,2,2])
M([1,2],[2,1],[2,1])
A1 = [2,2;2,1]; v = [2,1];
M(A1,v,1)
*****************************
ans =
14 12
14 12
14 12
13 11
i didnt get this ans, more precisely, im confused that what A1=[2,2;2,1] in M(A1,v,1) do???
************************************************************************

1 commentaire

KSSV
KSSV le 30 Oct 2018
It is indexing the matrix..read about MATLAB indexing.

Connectez-vous pour commenter.

 Réponse acceptée

Guillaume
Guillaume le 1 Nov 2018
This is all simple indexing which I thought was well explained in the doc
M([1,2],[2,1],[2,1])
returns row 1 and 2, column 2 and 1 (in that order) and page 2 and 1 (in that order) of M.
A1 = [2,2;2,1];
v = [2,1];
M(A1,v,1)
Note that the shape of A1 is irrelevant in the above. A1 = [2 2 2 1] would produce the same result. It returns row 2, then row 2 again, then row 2 again, then row 1 and column 2 and 1 (in that order) and page 1.
v(1) = index column 2
| v(2) = index column 1
| |
V V
14 12 <-- A1(1) = index row 2
14 12 <-- A1(2) = index row 2
14 12 <-- A1(3) = index row 2
13 11 <-- A1(4) = index row 1

2 commentaires

Dipraj Kadlag
Dipraj Kadlag le 1 Nov 2018
Modifié(e) : Dipraj Kadlag le 1 Nov 2018
Just alter v(1) and V(2) names, you labelled V2 as v1 and vice versa. Remaining all good. Same explaination I got myself earlier. Thanks! I'm accepting your answer.
Guillaume
Guillaume le 1 Nov 2018
Modifié(e) : Guillaume le 1 Nov 2018
Not sure I get you, the first column returned is column v(1), so column 2 and the 2nd column returned is v(2), so column 1.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by