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

2 vues (au cours des 30 derniers jours)
SNT
SNT le 14 Nov 2018
Commenté : SNT le 14 Nov 2018
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 commentaires
KSSV
KSSV le 14 Nov 2018
Whats the logic behind getting array4? Why the columns are being removed? Is there any criteria?
SNT
SNT le 14 Nov 2018
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!

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 14 Nov 2018
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) = [] ;

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by