Borrar filtros
Borrar filtros

How to return a mean value with NaN values in the matrix?

3 visualizaciones (últimos 30 días)
Seth
Seth el 20 de Mayo de 2013
I have written a piece of code which states if a number is > 1 or < 0.05 then it should return a NaN value:
if JumpHeightImpulse(i) > 1
JumpHeightImpulse(i) = 0;
end
if JumpHeightImpulse(i) < 0.05
JumpHeightImpulse(i) = 0;
end
end
And then I have tried to find the mean and standard deviation of my values using nanmean and nanstd:
for i = 1:length(NoS);
for j = 1:4
A = CombinedData(CombinedData(:,2)==i,:);
B = A(A(:,3)==j,:);
mean(i,j) = nanmean(B(:,5));
stdev(i,j) = nanstd(B(:,5));
end
end
However when I input this it returns NaN values for the mean and st dev. Any ideas as to why this is? Thanks
  2 comentarios
Iain
Iain el 20 de Mayo de 2013
Editada: Image Analyst el 20 de Mayo de 2013
We need more of the code. But you could try:
JumpHeightImpulse(JumpHeightImpulse > 1) = NaN;
JumpHeightImpulse(JumpHeightImpulse < 0.05) = NaN;
mean_vals = nanmean(JumpHeightImpulse);
std_vals = nanstd(JumpHeightImpulse);
Image Analyst
Image Analyst el 20 de Mayo de 2013
lain, make that an answer.

Iniciar sesión para comentar.

Respuestas (2)

Iain
Iain el 21 de Mayo de 2013
We need more of the code. But you could try:
JumpHeightImpulse(JumpHeightImpulse > 1) = NaN; JumpHeightImpulse(JumpHeightImpulse < 0.05) = NaN; mean_vals = nanmean(JumpHeightImpulse); std_vals = nanstd(JumpHeightImpulse);

Andrei Bobrov
Andrei Bobrov el 21 de Mayo de 2013
Editada: Andrei Bobrov el 21 de Mayo de 2013
% 1)
JumpHeightImpulse(JumpHeightImpulse < .5 | JumpHeightImpulse > 1) = nan;
% 2) CD - your CombinedData
m = length(NoS);
n = 4;
sv = CD(all(bsxfun(@le,CD(:,2:3),[m,n]),2) & CD(:,2) > 0,[2,3,5]);
your_mean = accumarray(sv(:,1:2),sv(:,3),[m, n],@nanmean,nan);
your_std = accumarray(sv(:,1:2),sv(:,3),[m, n],@nanstd,nan);

Community Treasure Hunt

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

Start Hunting!

Translated by