how to find max and min values of the plot

3 ビュー (過去 30 日間)
thestargazer
thestargazer 2016 年 7 月 21 日
コメント済み: thestargazer 2016 年 7 月 22 日
Hi,
Im plotting some data and I want to separate sections with colours. I am doing that with 'patch' but i want it to fill to maximal and minimal value of the plot window, for a section of the x-axis that I choose. My code:
figure; hold on;
I1 = power(7000:end);
t1 = time(7000:end);
plot(t1,I1,'.'); grid;
time1 = '15:48:30';
time2 = '15:51:30';
p=patch([datenum(time1,'HH:MM:SS') datenum(time2,'HH:MM:SS') ...
datenum(time2,'HH:MM:SS') datenum(time1,'HH:MM:SS')],...
[0.06 0.06 0.105 0.105],'r'); % x, Y coord
set(p,'FaceAlpha',0.1);
I don't want to enter these numbers manually. How can it find the max and min the plot with plot the data with and automatically size the patch to fill along the y-axis for entered x values?

回答 (1 件)

Guillaume
Guillaume 2016 年 7 月 21 日
You can get the axis range from its XLim and YLim properties, which you can query with either get(gca, 'YLim') or simply ylim:
p = patch([datenum(time1,'HH:MM:SS') datenum(time2,'HH:MM:SS') ...
datenum(time2,'HH:MM:SS') datenum(time1,'HH:MM:SS')],...
reshape([ylim; ylim], 1, []),'r');
  1 件のコメント
thestargazer
thestargazer 2016 年 7 月 22 日
Hi, Im getting the following error when using this code: reshape([ylim; ylim], 1, []),'r');
Error: File: processdata.m Line: 46 Column: 48 Expression or statement is incorrect--possibly unbalanced (, {, or [.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by