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 Kommentar

KSSV
KSSV am 30 Okt. 2018
It is indexing the matrix..read about MATLAB indexing.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Guillaume
Guillaume am 1 Nov. 2018

0 Stimmen

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 Kommentare

Dipraj Kadlag
Dipraj Kadlag am 1 Nov. 2018
Bearbeitet: Dipraj Kadlag am 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 am 1 Nov. 2018
Bearbeitet: Guillaume am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by