How to sum up values in a column of array2 to a column in array1

조회 수: 2 (최근 30일)
SNT
SNT 2018년 11월 14일
댓글: SNT 2018년 11월 14일
Hello!
I have two arrays as below;
array1 = [1 2 3 4 5 6 7 8; 9 10 11 12 13 14 15 16 ; 17 18 19 20 21 22 23 24] % 8 columns and 3 rows
array2 = [100; 200; 300] % 1 column 3 rows
I would like to add the values in array2 to the 7th column of array1 to make new array3
array3 = [1 2 3 4 5 6 107 8; 9 10 11 12 13 14 215 16 ; 17 18 19 20 21 22 323 24]
Then I would like to make a new array4 which includes only few of the columns of array3;
array4 = [2 5 6 107; 10 13 14 215 ; 18 21 22 323]
The arrays here are just for illustration. My actual array1 has 8 columns and many(n) rows, while my actual array2 has 1 column and many(n) rows, so I need something that can handle a variable number of rows..
Would be great if someone could give me a helping hand with this!
Thanks a lot in advance!
  댓글 수: 2
KSSV
KSSV 2018년 11월 14일
Whats the logic behind getting array4? Why the columns are being removed? Is there any criteria?
SNT
SNT 2018년 11월 14일
Hi KSSV, I need to save the array as an input for another software, and that is why I would like to sort and arrange the columns accordingly before saving as an excel sheet at the end. Thanks!

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

채택된 답변

KSSV
KSSV 2018년 11월 14일
array1 = [1 2 3 4 5 6 7 8; 9 10 11 12 13 14 15 16 ; 17 18 19 20 21 22 23 24] % 8 columns and 3 rows
array2 = [100; 200; 300] % 1 column 3 rows
array3 =array1 ;
array3(:,7) = array3(:,7)+array2 ;
idx = [1 3 4 8] ; % remove these columns
array4 = array3 ;
array4(:,idx) = [] ;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by