简体   繁体   中英

Matlab - concentration vs distance plot (2D)

I have several sets of data. Each set is a list of numbers which is the distance from 0 that a particle has travelled. Each set is associated with a finite time, so set 1 is the distances at T=0; set 2 is the distances at T=1 and so on. The size of each set is the total number of particles and the size of each set is the same.

I want to plot a concentration vs distance line.

For example, if there are 1000 particles (the size of the sets); at time T=0 then the plot will just be a straight line x=0 because all the particles are at 0 (the set contains 1000 zeroes). So the concentration at x=0 =100% and is 0% at all other distances

At T=1 and T=2 and so on, the distances will increase (generally) so I might have sets that look like this: (just an example)

T1 = (1.1,2.2,3.0,1.2,3.2,2.3,1.4...) etc T2 = (2.9,3.2,2.6,4.5,4.3,1.4,5.8...) etc

it is likely that each number in each set is unique in that set

The aim is to have several plots (I can eventually plot them on one graph) that show the concentration on the y-axis and the distance on the x-axis. I imagine that as T increases T0, T1, T2 then the plot will flatten until the concentration is roughly the same everywhere.

The x-axis (distance) has a fixed maximum which is the same for each plot. So, for example, some sets will have a curve that hits zero on the y-axis (concentration) at a low value for x (distance) but as the time increases, I envisage a nearly flat line where the line does not cross the x-axis (concentration is non-zero everywhere)

I have tried this with a histogram, but it is not really giving the results I want. I would like a line plot but have to try and put the distances into common-sense sized bins.

thank you W

浓度图

some rough data

Y1 = 1.0e-09 * [0.3358, 0.3316, 0.3312, 0.3223, 0.2888, 0.2789, 0.2702,...
    0.2114, 0.1919, 0.1743, 0.1738, 0.1702, 0.0599, 0.0003, 0, 0, 0, 0, 0, 0];

Y2 = 1.0e-08 * [0.4566, 0.4130, 0.3439, 0.3160, 0.3138, 0.2507, 0.2483,...
    0.1714, 0.1371, 0.1039, 0.0918, 0.0636, 0.0502, 0.0399, 0.0350, 0.0182,...
    0.0010, 0, 0, 0];

Y3 = 1.0e-07 * [0.2698, 0.2671, 0.2358, 0.2250, 0.2232, 0.1836, 0.1784,...
    0.1690, 0.1616, 0.1567, 0.1104, 0.0949, 0.0834, 0.0798, 0.0479, 0.0296,...
    0.0197, 0.0188, 0.0173, 0.0029];

These data sets contain the distances of just 20 particles. The Y0 set is zeros. I will be dealing with thousands, so the data sets will be too large.

Thankyou

Well, basically, you just miss the hold command. But first, put all your data in one matrix, like this:

Y = [1.0e-09 * [0.3358, 0.3316, 0.3312, 0.3223, 0.2888, 0.2789, 0.2702,...
    0.2114, 0.1919, 0.1743, 0.1738, 0.1702, 0.0599, 0.0003, 0, 0, 0, 0, 0, 0];
    1.0e-08 * [0.4566, 0.4130, 0.3439, 0.3160, 0.3138, 0.2507, 0.2483,...
    0.1714, 0.1371, 0.1039, 0.0918, 0.0636, 0.0502, 0.0399, 0.0350, 0.0182,...
    0.0010, 0, 0, 0];
    1.0e-07 * [0.2698, 0.2671, 0.2358, 0.2250, 0.2232, 0.1836, 0.1784,...
    0.1690, 0.1616, 0.1567, 0.1104, 0.0949, 0.0834, 0.0798, 0.0479, 0.0296,...
    0.0197, 0.0188, 0.0173, 0.0029]];

Then you need to plot each time step separately, and use the hold on to paste them on the same axes:

hold on
for r = size(Y,1):-1:1
    histogram(Y(r,:));
end
hold off
T_names = [repmat('T',size(Y,1),1) num2str((size(Y,1):-1:1).')];
legend(T_names)

Which will give you (using the example data): 多个直方图

Notice, that in the loop I iterate on the rows backwards - that's just to make the narrower histograms plot on the wider, so you can see all of them clearly.

EDIT

In case you want continues lines, and not bins, you have to first get the histogram values by histcounts , then plot them like a line:

hold on
for r = 1:size(Y,1)
    [H,E] = histcounts(Y(r,:));
    plot(E,[H(1) H])
end
hold off
T_names = [repmat('T',size(Y,1),1) num2str((1:size(Y,1)).')];
legend(T_names)

With your small example data it doesn't look so impressive though: 多行直方图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM