Info

This question is closed. Reopen it to edit or answer.

Generating a matrix using other matrixes

1 view (last 30 days)
alexaa1989
alexaa1989 on 12 Aug 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
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 Comment
Michael Haderlein
Michael Haderlein on 12 Aug 2014
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);

Answers (0)

Community Treasure Hunt

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

Start Hunting!