How to return a mean value with NaN values in the matrix?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Iain
le 20 Mai 2013
Modifié(e) : Image Analyst
le 20 Mai 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);
Réponses (2)
Iain
le 21 Mai 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);
0 commentaires
Andrei Bobrov
le 21 Mai 2013
Modifié(e) : Andrei Bobrov
le 21 Mai 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);
0 commentaires
Voir également
Catégories
En savoir plus sur Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!