フィルターのクリア

Problem in calculating median and average values at specific intervals.

1 回表示 (過去 30 日間)
Zhou Ci
Zhou Ci 2021 年 9 月 9 日
編集済み: Zhou Ci 2021 年 9 月 14 日
Hello everyone,
My text file contains three parameters Temp (in Kelvin), Ph, and Rad values. These values are extracted from hdf file. For every 1K interval there are several phase pixels. For example at 250K there can be 5 pixels (1st pixel can be 2, 2nd pixel can be 3 and so on.
-All these 5 pixels have corresponding Rad values (e.g. 25, 35, 20 ,15, 32). I want to calculate median of these pixels corresponding to Temperature value. For example at 250K median of above five Radius values will be 25.
-Secondly at this temperature interval I also want the average of Phase values. For example if at 250K there are 5 pixels with values (2,3,4,3,3), average will be 3.
Please find attached data. I'll be very grateful for the help.
My code doesn't give me desired result.
temperature_rounded=round(Temp,0);
T=unique(temperature_rounded);
Z=NaN(size(T));
for n=1:numel(T)
L= temperature_rounded==T(n); %select all positions where the rounded temperature is a specific value
Z(n)=median(Radius(L));%calculate the median for this selection
end

採用された回答

Matt J
Matt J 2021 年 9 月 9 日
編集済み: Matt J 2021 年 9 月 10 日
valid=(Phase~=0);
G=findgroups(round(Temp(valid),0));
Radius=Radius(valid);
Phase=Phase(valid);
medianRadius=splitapply(@median,Radius,G);
meanPhase=splitapply(@mean,Phase,G);
  2 件のコメント
Zhou Ci
Zhou Ci 2021 年 9 月 10 日
Hi Matt,
Using above lines of code gives me error at this line;
Radius=Radius(valid);
The logical indices contain a true value outside of the array bounds.
Secondly, is this typo error:
Phase=Phase(ivalid); % ivalid
Matt J
Matt J 2021 年 9 月 10 日
編集済み: Matt J 2021 年 9 月 10 日
Using above lines of code gives me error at this line;
Temp, Phase, and Radius are assumed by my solution to all be the same size.
Secondly, is this typo error:
Yes, I've fixed it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDenoising and Compression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by