Info
此问题已关闭。 请重新打开它进行编辑或回答。
swap a matrix using two vectors
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
the cyclist
2014-4-24
[~,idx] = ismember(b,an)
b_swapped = bn(idx)
3 个评论
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!