Finding the mean at each interval
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi everyone,
I have data containing 2 columns; Temperature and V. Temp contain repititive temperature values and V contains (2,3 and 4). What I want is that for each 1°C temperature I want the mean of values in V. For example at 12°C, a number of values (2,2,3,4,4,2,2) fall in this inteval (12°C), so, therfore at 12°C = 2.7. Any suggestions how to do this? Data is attached. Thank you
0 comentarios
Respuestas (2)
Mathieu NOE
el 22 de Sept. de 2021
hello
my 2 cents suggestion - see if for the empty intervals you prefer naN output (red dots) or you prefer interpolated data (black dots)
plot
code :
clc
clearvars
Tab = readtable('Data.xlsx') ;
T = Tab.Temp ;
V = Tab.V ;
[Ts,ind] = sort(T); % sort T in ascending order
Vs = V(ind);
minT = floor(min(Ts));
maxT = ceil(max(Ts));
Tnew = minT-0.5:1:maxT+0.5; % interval like -10.5 to 10.5
Tplot = minT:1:maxT; % corresponding center value (10)
for ci =1:length(Tnew)-1
ind = find(Ts>=Tnew(ci) & Ts<=Tnew(ci+1));
if ~isempty(ind)
Vmean(ci) = mean(Vs(ind));
else
Vmean(ci) = NaN;
end
end
% optionnal : remove NaN (missing) values by pchip interpolation
Vmean2 = interp1(Tplot,Vmean,Tplot,'pchip');
figure(1)
plot(Ts,Vs,'b',Tplot,Vmean,'-dr',Tplot,Vmean2,'*k');
legend('raw data (sorted)','averaged (including NaNs)','averaged (interpolated)');
0 comentarios
Ver también
Categorías
Más información sobre Point Cloud Processing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!