Combine each column of two array side by side and add new column to new array
32 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yen Su
el 1 de Feb. de 2021
Comentada: Yen Su
el 1 de Feb. de 2021
I have two array such as array1=[0.6 0.7 0.8; 0.2 0.5 0.25; 0.9 0.7 0.1] and array2=[11 12 13; 17 18 19; 21 24 26]. What I would like to do is I want to combine array1 and array2 such that in new array i can show each column of array1 and array 2 side by side and add new column which is sum of column1 of array1 and column1 of array2 to new array.
for e.g my new array will be
newarray=[0.6 11 (11+0.6) 0.7 12 (12+0.7) 0.8 13 13.8;0.2 17 17.2 0.5 18 18.5 0.25 19 19.25;0.9 21 21.9 0.7 24 24.7 0.1 26 26.1]
How do I do this? Any advice please.
0 comentarios
Respuesta aceptada
Stephen23
el 1 de Feb. de 2021
Editada: Stephen23
el 1 de Feb. de 2021
A = [0.6 0.7 0.8; 0.2 0.5 0.25; 0.9 0.7 0.1]
B = [11 12 13; 17 18 19; 21 24 26]
C = reshape([A;B;A+B],size(A,1),[])
Más respuestas (1)
David Hill
el 1 de Feb. de 2021
array1=array1';
array2=array2';
array3=array1+array2;
newArray=reshape([array1(:),array2(:),array3(:)]',9,[])';
Ver también
Categorías
Más información sobre Operators and Elementary Operations 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!