Azzera filtri
Azzera filtri

How to write a point's coordinates

4 visualizzazioni (ultimi 30 giorni)
Jacked Daniel
Jacked Daniel il 28 Nov 2019
Risposto: Nihal il 12 Giu 2024
How can I write coordinates of my extrema on a figure?
I tried using "text" command but I stiil can't deal with the problem

Risposte (1)

Nihal
Nihal il 12 Giu 2024
To write the coordinates of extrema (maximum and minimum points) on a figure in MATLAB, you can indeed use the text command effectively. Here's a step-by-step guide on how to identify the extrema of a given dataset or function and then annotate these points on a figure.
Let's assume you have a simple dataset or a function for which you want to find and annotate the extrema. I'll provide examples for both scenarios.
For a Dataset
Assuming you have x and y vectors representing your data.
x = 1:10; % Example x data
y = [2 3 1 5 6 4 7 8 6 9]; % Example y data
% Find the indices of the min and max
[ymax, imax] = max(y);
[ymin, imin] = min(y);
% Plot the data
plot(x, y, '-o'); % Plot with markers at each data point
hold on; % Keep the plot for further plotting
% Annotate the max
text(x(imax), ymax, sprintf('Max: (%d, %d)', x(imax), ymax), 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'right');
% Annotate the min
text(x(imin), ymin, sprintf('Min: (%d, %d)', x(imin), ymin), 'VerticalAlignment', 'top', 'HorizontalAlignment', 'right');
hold off; % Release the plot
Tips
  • Adjust the 'VerticalAlignment' and 'HorizontalAlignment' properties in the text command to better position your annotations relative to the extrema points.
  • Use sprintf to format the text string with the coordinates.
  • If dealing with complex functions or large datasets, consider using numerical methods or built-in functions like findpeaks for more sophisticated extrema detection.
This should help you annotate the extrema on your figures effectively. If you encounter any specific issues, please provide more details about the problem you're facing. I hope it helps.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by