필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

swap a matrix using two vectors

조회 수: 1 (최근 30일)
Anusha
Anusha 2014년 4월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
an =
2
3
5
6
0
1
4
bn =
4
5
1
3
2
6
0
I need to swap these two vectors in the matrix b =
4 3 2 5
1 0 6 2
3 2 5 1
  댓글 수: 1
Anusha
Anusha 2014년 4월 24일
all the 2 becomes 4 ,3 becomes 5,5 becomes 1.,etc

답변 (1개)

the cyclist
the cyclist 2014년 4월 24일
[~,idx] = ismember(b,an)
b_swapped = bn(idx)
  댓글 수: 3
Anusha
Anusha 2014년 4월 24일
only direct swap only. 2 to 4 and 4 to 0 directly.. no swap 2 to 0
the cyclist
the cyclist 2014년 4월 24일
My algorithm does direct swap only. Run this code:
an = [2 3 5 6 0 1 4];
bn = [4 5 1 3 2 6 0];
b = [4 3 2 5; ...
1 0 6 2; ...
3 2 5 1];
[~,idx] = ismember(b,an);
b_swapped = bn(idx)
I get
b_swapped =
0 5 4 1
6 2 3 4
5 4 1 6
Isn't this exactly what you want?

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by