How to return a mean value with NaN values in the matrix?
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Iain
2013 年 5 月 20 日
編集済み: Image Analyst
2013 年 5 月 20 日
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);
回答 (2 件)
Iain
2013 年 5 月 21 日
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 件のコメント
Andrei Bobrov
2013 年 5 月 21 日
編集済み: Andrei Bobrov
2013 年 5 月 21 日
% 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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!