Borrar filtros
Borrar filtros

How can I subtract the values of each two columns in a big matrix?

12 visualizaciones (últimos 30 días)
Rt Ro
Rt Ro el 2 de Ag. de 2019
Comentada: Rt Ro el 2 de Ag. de 2019
I have a matrix 13*8 with max and min temperatures. I want to subtract the value of first column from the value of second column for each two columnas and for all rows.
for Exp:
in column 1 the first row: 11.15 - ( -0.5)
in column 3 the first row: 7.89 - ( -2.7)
I obtained the mean with this code:
r = rand(16, 10000);
s = reshape(r, 16, 1000, 10);
t = squeeze(mean(s, 2));
but I don't know what should I do for the substraction.
could you please help me?
  2 comentarios
Adam
Adam el 2 de Ag. de 2019
Sounds like just something like
myMatrix( :, 1:2:end ) - myMatrix( :, 2:2:end);
should work, where myMatrix is your matrix loaded into Matlab, and assuming it always had an even number of columns, as in your example.
Rt Ro
Rt Ro el 2 de Ag. de 2019
Thanks a lot. it is working well.

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 2 de Ag. de 2019
I'm going to make a 10-by-4 matrix of sample data consisting of integer values between 0 and 100 inclusive.
A = randi([0 100], 10, 4)
To subtract one column from another:
threeMinusOne = A(:, 3)-A(:, 1)
If you're using release R2016b or later, if you want to subtract one column from all the other columns, you can do that using implicit expansion. For earlier releases you can do the same thing, but it's a bit more verbose and complicated since you'd need to use the bsxfun function.
allMinusOne = A - A(:, 1)
allMinusOnePre16b = bsxfun(@minus, A, A(:, 1))
doTheyMatch = isequal(allMinusOne, allMinusOnePre16b)

Categorías

Más información sobre Develop Apps Using App Designer 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