MATLAB Answers

How to plot individual data on a 2D line graph

17 ビュー (過去 30 日間)
Grace Rembold
Grace Rembold 2019 年 11 月 20 日
コメント済み: Erivelton Gualter 2019 年 11 月 21 日
I'm being asked to plot the Maximum value of a set of data in a different color and shape from the rest of the line. my code currently looks like this:
subplot(2,1,1)
xdata=[timeh];
y1data=[X];
y1data_max=max(X);
plot(xdata, y1data);
how would i also include y1data_max in my plot in say, a red circle?

  0 件のコメント

サインイン to comment.

回答 (1 件)

Erivelton Gualter
Erivelton Gualter 2019 年 11 月 20 日
編集済み: Erivelton Gualter 2019 年 11 月 20 日
See the following example:
% Sample Data
x = 0:.1:2*pi;
y = sin(x);
% Find maximun value
[max_point, idx] = max(y);
figure; hold on;
plot(x,y); % Fisrt Plot
plot(x(idx), y(idx), 'or') % Red circle at maximum valum
See references:

  3 件のコメント

Grace Rembold
Grace Rembold 2019 年 11 月 21 日
this is fine, but I'm not really sure how to execute this when I make a subplot. Also, this order makes it so the line " plot(x(idx), y(idx), 'or') " supercedes the line " plot(x,y); ". this makes it so on my plot, only the red circle appears on the plot, and the line doesnt.
Erivelton Gualter
Erivelton Gualter 2019 年 11 月 21 日
It is the same for a subplot.
% Sample Data
x = 0:.1:2*pi;
y = sin(x);
% Find maximun value
[max_point, idx] = max(y);
figure;
% Subplot 1
subplot(211); hold on;
plot(x,y); % Fisrt Plot
% Subplot 1
subplot(212); hold on;
plot(x,y); % Fisrt Plot
plot(x(idx), y(idx), 'or') % Red circle at maximum valum
Dont forget to use hold on . It keep the plots , until you use hold off.
Erivelton Gualter
Erivelton Gualter 2019 年 11 月 21 日
For your code, it might be something like in the following:
xdata=[timeh];
y1data=[X];
y1data_max=max(X);
subplot(2,1,1); hold on;
plot(xdata, y1data);
plot(xdata_max, y1data_max,'or') ;

サインイン to comment.

サインイン してこの質問に回答します。

製品


リリース

R2019b

Translated by