How to display the coordinate of the point in the figure

The problem is similar to this but I have an x-axis that decreases from 1 to 0 at increments of 0.1 https://www.mathworks.com/matlabcentral/answers/89104-how-to-display-the-coordinate-of-the-point-in-the-figure
for k=1:numel(x)
text(x(k),y(k),['(' num2str(x(k)) ',' num2str(y(k)) ')'])
end
I also need to adjust the window for this but axis won't work because it only applies for increases x-values.
Can someone advise me how to accommodate for these changes?

回答(3 个)

This is the output image of what I'm getting.
You can see the points are not following the curve.
The labels are being put into the proper place on the graph. Your third point is at y = -3.something which happens to be outside the range of what you are displaying. That is not the fault of text(), that is because you have told it coordinates that are not on your graph.

5 个评论

Ok that's not how the labels should be.
Values of f are as follows:
f = [ 0.99 , 0.77, 0.55, 0.33 ]
The two functions I'm plotting are as follows:
y1 = @(f)(-14.2 +1000.0) * f.^(1.02 - 1.0) - 1000.0;
y2 = @(newvariable) (1.02 * (newvariable +1000.0) - 1000.0)
What you see in the plot is a plot of y1 and y2 with f values.
ax1 = plot( f , y1(f), '--', f, y1(f), 'o' ) ;
hold on;
ax2 = plot( f , y2(y1(f)), '--', f,y2(y1(f)), 'o' )
There should be 8 points labeled but I can only show it for one and it's not done correctly.
I also need to extrapolate to f=0, what am I not doing correctly?
That code does not produce the plot you show above, not even if you set(gca,'xdir','reverse') to reverse the X axes. The upper line that is plotted in your image is about 5 units lower than the actual y2(y1(f)) value. Meanwhile the third text label that is to the upper right and outside the graph appears to be at the correct y2(y1(f)) value.
Side note: you can make your plotting shorter, using just a single statement.
h = plot( f , y1(f), '--o', f, y2(y1(f)), '--o' )
I would, by the way, not call the result ax1 as the result of plot() is line objects, not axes objects.
Well the plot line you provided works and if I use set(gca,'xdir','reverse') it gets what I want - see attached image.
There are two things I would like to do with this: The first is plot all 8 points on the two functions and the second extrapolate these functions as they approach 0.
clf
f = [ 0.99 , 0.77, 0.55, 0.33 ];
y1 = @(f)(-14.2 +1000.0) * f.^(1.02 - 1.0) - 1000.0;
y2 = @(newvariable) (1.02 * (newvariable +1000.0) - 1000.0);
y1f = y1(f);
y2y1f = y2(y1f);
y1_0 = fzero(y1,[0,realmax]);
y2y1_0 = fzero(@(x) y2(y1(x)),[0,realmax]);
h = plot( f , y1f, '--ob', f, y2y1f, '--ok', y1_0, 0, '*r', y2y1_0, 0, '*g' );
set(gca, 'xdir', 'reverse')
XY = [f(:), y1f(:); f(:), y2y1f(:); y1_0, 0; y2y1_0, 0];
labels = cellstr([num2str(XY(:,1)),repmat(', ',size(XY,1),1),num2str(XY(:,2))]);
text(XY(:,1), XY(:,2), labels);
legend(h, {'y1(x)', 'y2(y1(x))', 'y1(x) = 0', 'y2(y1(x)) = 0'}, 'location', 'southwest');
The red and green star, what is the purpose of this? It's not a necessary point, I just want to show the 8 points and extrapolate the end of the function as f approaches 0.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Graphics Performance 的更多信息

标签

提问:

T
T
2016-1-24

Community Treasure Hunt

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

Start Hunting!

Translated by