How can I show a certain value in a certain position in the figure?

Hello,
I want to a specific value in the figure. 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.

 Accepted Answer

Here is a quick example. If you do not have an equation you can still solve for the 0.9 value using numerical methods but the key is the text function.
% Some equation
syms x
eq = 0.2*x;
% Solve for x coord
S = vpasolve(eq == 0.9, x)
% Plot
fplot(eq)
% Add labels
hold on
plot(S, 0.9, 'o')
text(S, 0.9, string(S))
hold off

13 Comments

Actually, I dont have any equation. I have only a long array from where I am counting my CDF and plot it.
I am sorry, I cannot understand your example perfectly.
If you just have data use the interp1 function to find the x value that corresponds to your y value. So it would look something like this:
% X and y values for one data series
x = [...]
y = [...]
% Interpolate the x value for a y value of 0.9
xq = interp1(y,x,0.9)
% Plot the data
plot(x,y)
% Add a circle and text at the area of interest
hold on
plot(xq, 0.9, 'o')
text(xq, 0.9, string(xq))
hold off
You may want to use a different interpolation method depending on how accurate you need the labels and how many data points you have. Read the documentation in the link I provided for more information.
Thank you so very much for your kind reply.
It works fine for the smaller dataset when I checked it. But when I am trying use in my dataset I am having problem. Like data must be unique. Problem is that in my dataset there is no specific point of 0.9. It may 0.980000012 this way. I am attaching here my dataset for your kind considerations.
I am sorry, I went to the link you provided. I can set the range but how can I get that point value which is very very close to 0.9?
I dont fully understand your problem. Please post your code as I got an answer that made sense by just interpolating.
This is my code. I generalize my code. I store my original data output into the variabes, X1_axes, Y1_axes, X2_axes and Y_2axes.
Then I am plotting them in the figure. As I marked in the figure, I want to visulaize this data in my figure.
In your last code, it was perfectly work for small data.
Thank you for time and considerations.
Try this (I removed your data set, you just need to copy and paste it back in at the start):
% Find values of interest
xq1 = interp1(Y1_axes,X1_axes,0.9);
xq2 = interp1(Y2_axes,X2_axes,0.9);
% Make the main plot
figure('name','figure','NumberTitle','off');
plot(X1_axes, Y1_axes,'-r')
hold on
plot(X2_axes,Y2_axes,'-g')
hold off
% Add first marker
hold on
plot(xq1, 0.9, 'ko')
text(xq1, 0.85, num2str(xq1))
hold off
% Add secound marker
hold on
plot(xq2, 0.9, 'ko')
text(xq2, 0.95, num2str(xq2))
hold off
% Formatting
xlabel('time error')
ylabel('CDF')
set(gca,'YTick',0:0.1:1)
Thank you so much.
What is the purpose of 0.85 in this line, text(xq1, 0.85, num2str(xq1)) and changed to 0.95 for another line.
Sorry to ask this, as I have more input to plot in the figure.
Why its different in different line?
It’s so that the text doesn’t interfere with each other. Just formatting.
Did you check with my dataset? When I am running this with this data, I am getting the same error like previous. Is there anything that I have to do?
>> xq1 = interp1(Y1_axes,X1_axes,0.9);
Error using griddedInterpolant
The grid vectors must contain unique points.
Error in interp1 (line 151)
F = griddedInterpolant(X,V,method);
I had no problem. You can see the plot that I generated a few posts back.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!