Combine each column of two array side by side and add new column to new array

조회 수: 32 (최근 30일)
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.

채택된 답변

Stephen23
Stephen23 2021년 2월 1일
편집: Stephen23 2021년 2월 1일
A = [0.6 0.7 0.8; 0.2 0.5 0.25; 0.9 0.7 0.1]
A = 3×3
0.6000 0.7000 0.8000 0.2000 0.5000 0.2500 0.9000 0.7000 0.1000
B = [11 12 13; 17 18 19; 21 24 26]
B = 3×3
11 12 13 17 18 19 21 24 26
C = reshape([A;B;A+B],size(A,1),[])
C = 3×9
0.6000 11.0000 11.6000 0.7000 12.0000 12.7000 0.8000 13.0000 13.8000 0.2000 17.0000 17.2000 0.5000 18.0000 18.5000 0.2500 19.0000 19.2500 0.9000 21.0000 21.9000 0.7000 24.0000 24.7000 0.1000 26.0000 26.1000
  댓글 수: 3
Stephen23
Stephen23 2021년 2월 1일
편집: Stephen23 2021년 2월 1일
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];
D = [sum(A,2),sum(B,2),sum(A+B,2)]
D = 3×3
2.1000 36.0000 38.1000 0.9500 54.0000 54.9500 1.7000 71.0000 72.7000
Yen Su
Yen Su 2021년 2월 1일
where do we put D in C to see D table in C?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Hill
David Hill 2021년 2월 1일
array1=array1';
array2=array2';
array3=array1+array2;
newArray=reshape([array1(:),array2(:),array3(:)]',9,[])';

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by