简体   繁体   English

如何在MATLAB中的图中找到特定点?

[英]How can I find a specific point in a figure in MATLAB?

I want a specific value in the figure in MATLAB.我想要在 MATLAB 图中的特定值。 I put the black circle and arrow manually through the figure insert option.我通过图形插入选项手动放置黑色圆圈和箭头。 But How can I set the value now?但是我现在如何设置值? I want the x-axes values that are exactly 90% of each CDF curve.我想要 x 轴值恰好是每条 CDF 曲线的 90%。 here I am attaching my MatLab figure in jpg mode.在这里,我以 jpg 模式附加了我的 MatLab 图。

CDF 的图像

I would use interp1 to find the value.我会使用 interp1 来查找值。 I'll assume that your x variable is called x and your cdf value is called c.我假设您的 x 变量称为 x,而您的 cdf 值称为 c。 You can then use code like this to get the x value where c = 0.9.然后您可以使用这样的代码来获取 x 值,其中 c = 0.9。 This will work even if you don't have a cdf value at exactly 0.9即使您没有恰好为 0.9 的 cdf 值,这也将起作用

x_at_0p9 = interp1(c, x, 0.9);

Assuming that your values are x and Y (where x is a vector and the same for all curves) and Y is a matrix with the same number of rows and as many columns as there are curves;假设您的值是xY (其中x是一个向量并且所有曲线都相同)并且Y是一个矩阵,其行数和列数与曲线的数量相同; you just need to find the first point where Y exceeds 0.9:你只需要找到Y超过 0.9 的第一个点:

x = (0:0.01:pi/2)'; % time vector
Y = sin(x*rand(1,3))*10; % value matrix

% where does the values exceed 90%?
lg = Y>= 0.9;

% allocate memory
XY = NaN(2,size(Y,2));

for i = 1:size(Y,2)
    % find first entry of a column, which is 1 | this is an index
    idx = find(lg(:,i),1);

    XY(:,i) = [x(idx);Y(idx,i)];
end

plot(x,Y, XY(1,:),XY(2,:), 'o')

You plotted those figures by using:您使用以下方法绘制了这些数字:

plot(X,Y)

So, your problem is to find x_0 value that makes Y = 0.9.因此,您的问题是找到使 Y = 0.9 的 x_0 值。 You can do this:你可以这样做:

ii = (Y==0.9) % finding index
x_0 = X(ii) % using index to get x_0 value

Of course this will only work if your Y vector has exactly the 0.9 value.当然,这仅在您的 Y 向量恰好具有 0.9 值时才有效。

As this is not always the case you may want to get the x_0 value that first makes Y to be greater or equal than 0.9.由于情况并非总是如此,您可能希望获得首先使 Y 大于或等于 0.9 的 x_0 值。

Then you can do this:然后你可以这样做:

ii = find(Y>=0.9, 1) % finding index
x_0 = X(ii) % using index to get x_0 value

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

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