How to return a mean value with NaN values in the matrix?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Iain
am 20 Mai 2013
Bearbeitet: Image Analyst
am 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);
Antworten (2)
Iain
am 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 Kommentare
Andrei Bobrov
am 21 Mai 2013
Bearbeitet: Andrei Bobrov
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!