How to calculate a median value of each interval?

5 Ansichten (letzte 30 Tage)
Zhou Ci
Zhou Ci am 12 Jul. 2021
Beantwortet: Rik am 12 Jul. 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 Kommentare
Rik
Rik am 12 Jul. 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 am 12 Jul. 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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 12 Jul. 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)

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by