フィルターのクリア

How to calculate a median value of each interval?

4 ビュー (過去 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 Center および File ExchangeSwitches and Breakers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by