Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Issues with the for loop

1 回表示 (過去 30 日間)
Sophia
Sophia 2019 年 8 月 14 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
tt=0;
for i = 1:size(ids_2006,2) * size od ids_2006 is 212*119*177
for j = 1:size(ids_2006,3)
tt=tt+1;
i,j,tt
% size of mean_wint_rho is 119*177
% size of stdv_daily_2006 is 119*177
if (squeeze(ids_2006(tt,:,:)) < (mean_wint_rho(:,:) - 3*stdv_daily_2006(:,:)))
daily_2006 = squeeze(ids_2006(:,i,j));
new_daily_2006(tt,:,:) = daily_2006;
%size of new_daily_2006 should be 212*119*177
else
new_daily_2006(tt,:,:) = NaN;
end
end
end
I want to remove the bias from the daily dataset by removing the points that are three standard deviation from the mean.

回答 (1 件)

darova
darova 2019 年 8 月 15 日
This should work
new_daily_2006 = ids_2006*0;
for i = 1:size(ids_2006,1) %* size od ids_2006 is 212*119*177
% i,j,tt
% size of mean_wint_rho is 119*177
% size of stdv_daily_2006 is 119*177
if (squeeze(ids_2006(i,:,:)) < (mean_wint_rho(:,:) - 3*stdv_daily_2006(:,:)))
new_daily_2006(i,:,:) = squeeze(ids_2006(i,:,:));
%size of new_daily_2006 should be 212*119*177
else
new_daily_2006(i,:,:) = NaN;
end
end
The question is: when it will be work?
if (squeeze(ids_2006(i,:,:)) < (mean_wint_rho(:,:) - 3*stdv_daily_2006(:,:)))
Something like this
if ([1 0])
disp('hi')
end
Or maybe this
if any([1 0])
disp('hi')
end
  3 件のコメント
Sophia
Sophia 2019 年 9 月 16 日
I have finally figured the answer-
new_daily_2006 = [];
for t = 1:size(ids_2006,1)
for i = 1:size(ids_2006,2)
for j = 1:size(ids_2006,3)
temp = squeeze(ids_2006(t,i,j));
if (abs(temp) < stdv_daily_2006(i,j))
new_daily_2006(t,i,j) = temp;
else
new_daily_2006(t,i,j) = NaN;
end
end
end
end
darova
darova 2019 年 9 月 16 日
編集済み: darova 2019 年 9 月 16 日
Try also without loops
m = size(ids_2006);
temp = reshape(stdv_daily_2006,[1 size(stdv_dayly_2006)]); % make 1 x 119 x 177
cond = abs(ids_2006) < repmat(temp,[m 1 1]) % make 212 x 119 x 177
new_daily_2006(cond) = ids_2006;
new_daily_2006(~cond) = NaN;

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by