For loop with use of larger than

9 visualizaciones (últimos 30 días)
Yarne Schlösser
Yarne Schlösser el 3 de Mzo. de 2021
Comentada: Rik el 10 de Mzo. de 2021
I have this pressure-angle diagram in which the angle is plotted on the y axis and the pressure on the x-axis. The plot is made out of several data points.
The angle array is a 47245x1 array with values between -360 and 360).
The pressure array is also a 47245x1 array.
Now I want to calculate the average data value of the pressure for every small angle change.
I was thinking in way to sum of the data points between -360 degrees and -359.50 degrees divided by the length of these data points. I want to repeat this process for the complete range for the angle, but I cannot figure it out.

Respuestas (2)

KALYAN ACHARJYA
KALYAN ACHARJYA el 3 de Mzo. de 2021
Editada: KALYAN ACHARJYA el 3 de Mzo. de 2021
Now I want to calculate the average data value of the pressure for every small angle change.
Hint: Do modify accordingly
angle_data=......%Array
average_presure=zeros(1,length(angle_data));
for i=1:length(angle_data)
pressure_data= .......% Calculate Pressure based on angle(i)
average_presure(i)=mean(pressure_data);
end
  1 comentario
Yarne Schlösser
Yarne Schlösser el 10 de Mzo. de 2021
Thank you for your response. This one works, but takes a long time for matlab to calculate.

Iniciar sesión para comentar.


Rik
Rik el 3 de Mzo. de 2021
Editada: Rik el 3 de Mzo. de 2021
It sounds like one of the functions related to histcounts is appropriate here.
angles=rand(500,1)*2*360-360;
pressure=sind(angles)+rand(size(angles))/5;
[N,edges,bin] = histcounts(angles,100);
bin_centers=edges(2:end)-diff(edges)/2;
mean_pressure=accumarray(bin,pressure,[],@mean);
plot(angles,pressure,'.')
hold on,plot(bin_centers,mean_pressure,'LineWidth',2)
  1 comentario
Rik
Rik el 10 de Mzo. de 2021
Do you want to calculate the standard deviation for each bin separately, for the original data, or for mean_pressure?
In case it is the first, did you read the documentation for accumarray?
If my answer solved your issue, please consider marking it as accepted answer. Please use the tools explained on this page to format your posts.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by