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

2 visualizaciones (últimos 30 días)
SNT
SNT el 14 de Nov. de 2018
Comentada: SNT el 14 de Nov. de 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 comentarios
KSSV
KSSV el 14 de Nov. de 2018
Whats the logic behind getting array4? Why the columns are being removed? Is there any criteria?
SNT
SNT el 14 de Nov. de 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!

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 14 de Nov. de 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) = [] ;

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by