Matrix(Matrix)

4 ビュー (過去 30 日間)
Prabhat Hegde
Prabhat Hegde 2020 年 4 月 10 日
回答済み: nada zaidi 2021 年 4 月 6 日
I am a new MATLAB user and am unsure of what operation is being carried out by the below chunk of code.
a=[1 1;1 2]
b=[1;0;0;1]
b(a(:),:)
ans =
1
1
1
0
a(:)
^obviously gives the column vector of a.
(a(:),:)
^selects all rows and columns in this column vector.
b(a(:),:)
^what does this chunk of code do?

採用された回答

James Tursa
James Tursa 2020 年 4 月 10 日
編集済み: James Tursa 2020 年 4 月 10 日
The "a" values are simply being used as row numbers for indexing into b.
b(a(:),:)
= b([1;2;1;2],:)
which is equivalent to
[ b(1,:);
b(2,:);
b(1,:);
b(2,:)]
=
1
0
1
0

その他の回答 (1 件)

nada zaidi
nada zaidi 2021 年 4 月 6 日
B=A(2 -3 2 -4)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by