- 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.
How to write a point's coordinates
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Nihal
2024년 6월 12일
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!