How to calculate a median value of each interval?

조회 수: 5 (최근 30일)
Zhou Ci
Zhou Ci 2021년 7월 12일
답변: Rik 2021년 7월 12일
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
Rik
Rik 2021년 7월 12일
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 2021년 7월 12일
@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?

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2021년 7월 12일
%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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Switches and Breakers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by