简体   繁体   中英

How can I find a specific point in a figure in MATLAB?

I want a specific value in the figure in 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. here I am attaching my MatLab figure in jpg mode.

CDF 的图像

I would use interp1 to find the value. I'll assume that your x variable is called x and your cdf value is called c. You can then use code like this to get the x value where c = 0.9. This will work even if you don't have a cdf value at exactly 0.9

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; you just need to find the first point where Y exceeds 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. 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.

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.

Then you can do this:

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

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