# How to ignore certain columns in a matrix when calculating a mean across all columns in a matrix?

17 visualizaciones (últimos 30 días)
Tomaszzz el 16 de Mzo. de 2022
Comentada: Davide Masiello el 16 de Mzo. de 2022
Hi all,
I have a 100x16 double matrix (attached) which when plotted over one figure looks like this.
Now, I want to calculate the mean across all columns in the matrix so that the output is a 100x 1 double. I can do this by following
figure
plot(S_or_z(:,1:8),'r')
hold on
plot(S_or_z(:,9:end),'b')
% get mean
S_or_z_meancycle = mean(S_or_z, 2);
However, when calcuating the mean, I would like ignore the columns indicated in red.
The rule that I would like to apply is that the columns which range (max-min) exceeds 200 should be ignored when calcuating the mean accross all columns.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Davide Masiello el 16 de Mzo. de 2022
Editada: Davide Masiello el 16 de Mzo. de 2022
See if this works
new_S_or_z = S_or_z(:,(max(S_or_z,[],1)-min(S_or_z,[],1)) < 200);
Unrecognized function or variable 'S_or_z'.
plot(new_S_or_z)
mean(new_S_or_z,[],2)
##### 2 comentariosMostrar NingunoOcultar Ninguno
Tomaszzz el 16 de Mzo. de 2022
Thanks Davide,
mean(new_S_or_z,[],2)
Should it be?:
mean(new_S_or_z,2)
Otherwise I get:
Dimension argument must be a positive integer scalar, a vector of unique positive integers, or 'all'.
Davide Masiello el 16 de Mzo. de 2022
Yes, you're right! I got the syntax for "min" and "max" mixed up with the one for "mean", sorry about that.

Iniciar sesión para comentar.

### Categorías

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

### Community Treasure Hunt

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

Start Hunting!

Translated by