matrices

x=[1;4;5;6; 8; 9];
A=rand(6,6);
D1=[x A];
y=(1:10)';
B=rand(10,6);
D2=[y B];
I want to get matrix D3 which is equal to a horzcat of D1 and D2 such that D3 is of dimension 10x14 by matching x with y such that elements of x which are not in y will have nan in the row of D3 thanks for any help

Respuestas (1)

Jan
Jan el 19 de Feb. de 2012

1 voto

x = [1; 4; 5; 6; 8; 9];
A = rand(6,6);
D1 = [x A];
y = (1:10)';
B = rand(10,6);
D2 = [y B];
D3 = cat(2, NaN(10, 7), D2);
D3(ismember(y, x), 1:7) = D1;
If x is not sorted, you need the 2nd output of ismember.

1 comentario

Sara
Sara el 20 de Feb. de 2012
in one of the files which should be like all other am getting subscript mismatch error after the last line, i tried intesect just in case there are elements in x not in y but still got the same issue ..
one thing i notices is that when I run D3(ismember(y, x), 1:7) where the issue is, i get a matrix full of NaN, when i run ismember(y, x) I get a series of zeros and ones ... any suggestion is appreciated!

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation of 2-D Selections in 3-D Grids en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 19 de Feb. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by