How to create a loop which nan means every datapoint of three components
1 回表示 (過去 30 日間)
古いコメントを表示
I have 3 datasets at 11564597 data points each - my calculation is U = nanmean(sqrt((u).^2+(v).^2+(w).^2)); to get the mean flow of the 3 sinusoidal curves. To get an array that has 11564597 points to plot on top of the 3 components as the mean flow of the three compontents.
My code so far is:
U= NaN*ones(length(velocity_x_nortek.smooth));
for i = 1:length(velocity_x_nortek.smooth)
U(i)= nanmean(sqrt((velocity_x_nortek.smooth).^2+(velocity_y_nortek.smooth).^2+(velocity_z_nortek.smooth).^2);
end
0 件のコメント
採用された回答
ADragon
2018 年 9 月 6 日
Hi Rebecca, you do not need the for loop since the equation can operate on arrays. Just use:
U = nanmean(sqrt((velocity_x_nortek.smooth).^2+(velocity_y_nortek.smooth).^2+(velocity_z_nortek.smooth).^2);
plot([velocity_x_nortek.smooth velocity_y_nortek.smooth velocity_z_nortek.smooth U])
Assuming you have column vectors for plotting.
AD
6 件のコメント
ADragon
2018 年 9 月 7 日
編集済み: ADragon
2018 年 9 月 7 日
OK. You can add an index to your vector.
for i = 1:length(velocity_x_nortek.smooth)
U(i)= nanmean(sqrt((velocity_x_nortek.smooth(i)).^2+(velocity_y_nortek.smooth(i)).^2+(velocity_z_nortek.smooth(i)).^2));
end
But you will be taking the mean of a scalar value. So I am confused as to what you are trying to do...
If you are trying to calculate RMS then switch mean and sqrt.
for i = 1:length(velocity_x_nortek.smooth)
U(i)= sqrt(nanmean((velocity_x_nortek.smooth(i)).^2+(velocity_y_nortek.smooth(i)).^2+(velocity_z_nortek.smooth(i)).^2));
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!