How to display user defined data in a plot?

9 ビュー (過去 30 日間)
Joseph Stalin
Joseph Stalin 2017 年 11 月 8 日
回答済み: Aditya 2025 年 5 月 28 日 15:05
Hi, I have a data set , where I need to analyse for the max, min etc., Also I want to plot the data and want to display the max , min, values in the right side of plot itself . Please let me know how to do this..
Joseph

回答 (1 件)

Aditya
Aditya 2025 年 5 月 28 日 15:05
Hi Joseph,
To display user-defined data in a plot and show the minimum and maximum values in MATLAB, follow these steps:
  1. Load or define your dataset.
  2. Calculate the min and max values using "min()" and "max()".
  3. Plot the data using "plot()".
  4. Use "text()" or "annotation()" to display the values on the plot.
Example Code:
% Sample dataset
x = 1:10;
y = [3, 5, 2, 8, 6, 7, 4, 9, 1, 10];
% Find max and min values
max_val = max(y);
min_val = min(y);
% Plot the data
figure;
plot(x, y, '-o', 'LineWidth', 2);
xlabel('X-axis');
ylabel('Y-axis');
title('User-Defined Data Plot');
grid on;
% Display max and min values on the right side of the plot
text(max(x) + 0.1, max_val, sprintf('Max: %.2f', max_val), 'FontSize', 12, 'Color', 'red');
text(max(x) + 0.1, min_val, sprintf('Min: %.2f', min_val), 'FontSize', 12, 'Color', 'blue');
You can refer to the below MATLAB documentation to read more about this functions:
I hope this helps!

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by