Borrar filtros
Borrar filtros

How to calculate a median value of each interval?

4 visualizaciones (últimos 30 días)
Zhou Ci
Zhou Ci el 12 de Jul. de 2021
Respondida: Rik el 12 de Jul. de 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 comentarios
Rik
Rik el 12 de Jul. de 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 el 12 de Jul. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

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

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by