how to plot binned data?
Afficher commentaires plus anciens
Hi everyone,
I am trying to check the effect of aerosols concentration on temperature. I need to check the relation between temperature and aerosol conc. for each bin. This is my simple code for this work. I can't figure out how to make plot for these values. Using scatter gives me error because length of X and Y is not same. I need to place temperature on y-axis and aerosol concentration on x-axis. Data is attached. Thank you
Temp = Data(:,1);
Aer1 = Data(:,2);
[counts,edg,bin] = histcounts(Aer1)
counts =
85 4 4 1 0 2 1 2 0 1
edg =
1.0e-06 *
0 0.0300 0.0600 0.0900 0.1200 0.1500 0.1800 0.2100 0.2400 0.2700 0.3000
>> Med = accumarray(bin(:),Temp(:),[],@median)
Med =
-27.0000
-29.0000
-27.5000
-26.0000
0
-24.0000
-24.0000
-24.5000
0
-24.0000
Réponse acceptée
Plus de réponses (1)
Mathieu NOE
le 18 Mar 2022
hello
maybe this ?
you can change the number of bins (M)
Data = readmatrix('Data.xlsx');
Temp = Data(:,1);
Aer1 = Data(:,2);
M = 25; % histcounts uses M bins.
[counts,edg,bin] = histcounts(Aer1,M);
% Med = accumarray(bin(:),Temp(:),[],@median);
Med = accumarray(bin(:),Temp(:),[],@mean);
dx = mean(diff(edg));
xx = edg(1)+dx/2:dx:edg(end)-dx/2; % create a x axis centered (between edges)
ind = abs(Med)>0;% do not show Med values that are zero
plot(Aer1,Temp,'*',xx(ind),Med(ind),'-r');
Catégories
En savoir plus sur Scatter Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

