1

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

concentration graph

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

4

1 回答 1

0

好吧,基本上,您只是错过了hold命令。但首先,将所有数据放在一个矩阵中,如下所示:

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]];

然后您需要分别绘制每个时间步,并使用 将hold on它们粘贴到相同的轴上:

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)

这将为您提供(使用示例数据): 多个直方图

请注意,在循环中我向后迭代行 - 这只是为了使较窄的直方图绘制在较宽的位置上,这样您就可以清楚地看到所有这些直方图。

编辑

如果您想要继续线,而不是箱,您必须首先通过 获取直方图值histcounts,然后将它们绘制成一条线:

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)

使用您的小示例数据,它看起来并不那么令人印象深刻: 多线直方图

于 2016-08-08T20:54:57.820 回答