How to merge two different size matrix logically?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cladio Andrea
el 25 de Feb. de 2015
Editada: Cladio Andrea
el 25 de Feb. de 2015
Hello everyone, i have one matrix A = [0,1,2,...3600] and another one is B=[2,5,7,3600] what i want is to have matrix C(:,1)=[0,1,2....,3600] C(:,2)=[0,0,2,0,0,5,....3600] it should be as same size as A and if elements of B exist in A and that should be in the second column of C and the rest will be zero. Can you help please?
0 comentarios
Respuesta aceptada
Thorsten
el 25 de Feb. de 2015
Editada: Thorsten
el 25 de Feb. de 2015
Like this?
A = [0, 1, 2, 3, 4, 5, 7, 10];
B = [2, 5, 7];
C(:,1) = A;
C(end,2) = 0;
% ind = arrayfun(@(x)(find(x==A)), B);
% or
ind = find(ismember(A,B))
C(ind,2) = A(ind);
1 comentario
Cladio Andrea
el 25 de Feb. de 2015
Editada: Cladio Andrea
el 25 de Feb. de 2015
Más respuestas (2)
dpb
el 25 de Feb. de 2015
C=[A zeros(size(A)]; % allocate
C(ismember(A,B),2)=B; % merge by position
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!