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

2 次查看(过去 30 天)
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