How to create a loop which nan means every datapoint of three components

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

ADragon
ADragon am 6 Sep. 2018
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 Kommentare
Rebecca Ellis
Rebecca Ellis am 7 Sep. 2018
The calculation is
U = nanmean(sqrt((u).^2+(v).^2+(w).^2))
is correct -
I just need to loop it that it does the calculation for every 11564597 points -
U = zeros(length(timevec), 1);
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
The loop I have doesn't work ?
ADragon
ADragon am 7 Sep. 2018
Bearbeitet: ADragon am 7 Sep. 2018
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by