简体   繁体   English

Matlab - 浓度与距离图(2D)

[英]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. 每组都是一个数字列表,它是粒子行进的距离0。 Each set is associated with a finite time, so set 1 is the distances at T=0; 每组与有限时间相关联,因此组1是T = 0时的距离; set 2 is the distances at T=1 and so on. 第2组是T = 1时的距离,依此类推。 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); 例如,如果有1000个粒子(集合的大小); 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). 在时间T = 0时,该图将只是一条直线x = 0,因为所有粒子都在0(该组包含1000个零)。 So the concentration at x=0 =100% and is 0% at all other distances 因此,x = 0时的浓度= 100%,并且在所有其他距离处为0%

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) 在T = 1和T = 2等等,距离将增加(通常),所以我可能有这样的设置:(只是一个例子)

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 T1 =(1.1,2.2,3.0,1.2,3.2,2.3,1.4 ......)等T2 =(2.9,3.2,2.6,4.5,4.3,1.4,5.8 ......)等

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. 目的是有几个图(我最终可以在一个图上绘制它们),显示y轴上的浓度和x轴上的距离。 I imagine that as T increases T0, T1, T2 then the plot will flatten until the concentration is roughly the same everywhere. 我想,当T增加T0,T1,T2时,情节将变平,直到浓度在各处大致相同。

The x-axis (distance) has a fixed maximum which is the same for each plot. x轴(距离)具有固定的最大值,对于每个图都是相同的。 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) 因此,例如,一些集合将具有在y轴(浓度)处达到零的曲线,在x(距离)的低值处,但随着时间的增加,我设想一条近似平坦的线,其中线不穿过x轴(浓度在各处都是非零)

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. 这些数据集包含仅20个粒子的距离。 The Y0 set is zeros. Y0设置为零。 I will be dealing with thousands, so the data sets will be too large. 我将处理数千个,因此数据集太大了。

Thankyou 谢谢

Well, basically, you just miss the hold command. 好吧,基本上,你只是错过了hold命令。 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将它们粘贴到相同的轴上:

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: 如果你想要连续的行,而不是bin,你必须首先通过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)

With your small example data it doesn't look so impressive though: 使用您的小示例数据,它看起来并不那么令人印象深刻: 多行直方图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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