Info

此问题已关闭。 请重新打开它进行编辑或回答。

Generating a matrix using other matrixes

1 次查看(过去 30 天)
alexaa1989
alexaa1989 2014-8-12
关闭: MATLAB Answer Bot 2021-8-20
Hi everyone I need to use 3 different permutation matrixes to make a new one here's how I have it so far
n=randi([1 10],1,1);
x1=[randperm(n)];
x2=[randperm(n)];
o=[randperm(n)];
cc=randsample(n,2);
c1=min(cc);
c2=max(cc);
so far as you know I have produced 3 matrixes with same dimension and 2 random number which indicate the places between arrays not arrays themself.
now I need to produce Y with same dimension using x1 x2 and o with these constraints applied on Y :
from c1+1 to c2 I need to have arrays from c1+1 to c2 using x1 (exact same permutation)
from c2 to end I need to have arrays from o which are not in Y so far(exact same permutation)
from 1 to c1 I need to have those arrays from x2 that are not used in Y so far(exact same permutation)
to be more clear Y =[ something from x2 , something from x1 , something from o ]
can anyone help me?
  1 个评论
Michael Haderlein
Michael Haderlein 2014-8-12
Come on, that's your 5th question on the basically same problem. You should start writing code by yourself. I didn't follow all of the previous answers, so it might be that I present now techniques which are inferior to answers already posted.
On your question, I think the solution is
Y=nan(size(x1));
Y(c1+1:c2)=x1(c1+1:c2);
temp_o=o(~ismember(o,Y));
Y(c2+1:end)=temp_o(end-length(Y)+c2+1:end);
temp_x2=x2(~ismember(x2,Y));
Y(1:c1)=temp_x2(1:c1);

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by