Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
array operation for merging two arrays
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
sermet
el 20 de Mayo de 2016
Cerrada: Azzi Abdelmalek
el 20 de Mayo de 2016
data_1=[10;20;30;40];
data_2=[40;10];
data_3=[11;12];
for i=1:numel(data_2)
idx(i)=find(data_2(i)==data_1);
end
I need to merge data_2 and data_3 w.r.t idx array as follows;
merged_data=[10;11;12;40];
idx ([4 1]) determines the row number of 40 and 10 (data_2) within merged_data. Other row of the merged_data belongs to data_3.
data_2 and data_1 arrays always share at least 2 numbers. I need to merge data_2 and data_3 as an automatic way, keeping the order of rows w.r.t idx.
2 comentarios
Azzi Abdelmalek
el 20 de Mayo de 2016
Duplicate question here: http://www.mathworks.com/matlabcentral/answers/284994-adding-rows-to-array-with-order
Respuesta aceptada
Andrei Bobrov
el 20 de Mayo de 2016
Editada: Andrei Bobrov
el 20 de Mayo de 2016
union(intersect(data_1,data_2),data_3)
or
merge_data = data_1
merge_data(~ismember(merge_data,data_2)) = data_3
1 comentario
Más respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!