How can I show a certain value in a certain position in the figure?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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
Mark Sherstan
on 26 Dec 2019
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
Tania Islam
on 26 Dec 2019
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.
Mark Sherstan
on 26 Dec 2019
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.
Tania Islam
on 27 Dec 2019
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?
Mark Sherstan
on 27 Dec 2019
I dont fully understand your problem. Please post your code as I got an answer that made sense by just interpolating.
Tania Islam
on 27 Dec 2019
Thank you..
Tania Islam
on 27 Dec 2019
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.
Mark Sherstan
on 27 Dec 2019
Edited: Mark Sherstan
on 27 Dec 2019
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)
Tania Islam
on 28 Dec 2019
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?
Mark Sherstan
on 28 Dec 2019
It’s so that the text doesn’t interfere with each other. Just formatting.
Tania Islam
on 29 Dec 2019
Thank you so much
Tania Islam
on 29 Dec 2019
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);
Mark Sherstan
on 29 Dec 2019
I had no problem. You can see the plot that I generated a few posts back.
Tania Islam
on 30 Dec 2019
Thank you
More Answers (0)
Categories
Find more on Vector Fields in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)