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일

0 개 추천

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일

0 개 추천

B=A(2 -3 2 -4)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 4월 10일

답변:

2021년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by