Dynamically arrange the matrix in each for loop

1 次查看(过去 30 天)
I have two matrix a = [3 5 6 7] and b = [2 4 6 1; 5 7 8 9]. I need to dynamic arrange the matrix b when the position of a is changing.
For example,
First loop, a = [3 5 6 7]
b = [2 4 6 1
5 7 8 9]
But at the second loop, the position for b is changed a = [7 3 5 6]
b = [1 2 4 6
9 5 7 8]
and so on for the subsequent loop. Is this possible to happen? Thank you.

采纳的回答

Eric Pahlke
Eric Pahlke 2011-12-15
Definitely possible.
a = [3 5 6 7];
b = [2 4 6 1; 5 7 8 9];
for ii = 1:4
% do_stuff(a,b);
disp('iteration:')
disp(ii);
a
b
a = [a(end) a(1:end-1)];
b = [b(:,end) b(:,1:end-1)];
end
  4 个评论
Chin
Chin 2011-12-15
The problem is when a = [6 5 3 7]
i will get the result b = [6 4 2 1; 8 7 5 9]. Is that possible need to use indexing?
Andrei Bobrov
Andrei Bobrov 2011-12-15
x = a(randperm(4));
[loc,loc] = ismember(x,a);
b1 = b(:,loc)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by