How to calculate a median value of each interval?

5 vues (au cours des 30 derniers jours)
Zhou Ci
Zhou Ci le 12 Juil 2021
Réponse apportée : Rik le 12 Juil 2021
Hi everyone,
I want to make a line plot and for that purpose I need to calculate the median value of each interval. In my data Y (8767x1 double) is temperature and X (8767x1 double) is phase so I need to calculate the phase median value of each temperature interval such as 1 degree. And then plot it. Any suggestions how it can be done? Thank you.
Please find the attached data.
  6 commentaires
Rik
Rik le 12 Juil 2021
I meant selecting specific values from a vector. If you find out which positions round to the same degree, you can use that to calculate the median of only those values. If you do that in a loop, you will have found all relevant medians.
Zhou Ci
Zhou Ci le 12 Juil 2021
@Rik Sir, Can you please elaborate this line?
'If you find out which positions round to the same degree, you can use that to calculate the median of only those values'.
Secondly, how can it be done using loop?

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 12 Juil 2021
%generate some random data
temperature=15+10*rand(8767,1);
phase=360*rand(size(temperature));
temperature_rounded=round(temperature,0);
T=unique(temperature_rounded);
P=NaN(size(T));
for n=1:numel(T)
L= T==T(n); %select all positions where the rounded temperature is a specific value
P(n)=median(phase(L));%calculate the median for this selection
end
plot(T,P)

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by