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 Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by