Segment of Graph Extraction

3 ビュー (過去 30 日間)
Daniel
Daniel 2011 年 6 月 17 日
Can you use any plotting tools to extract a segment of a graph and replot that segment into a new figure or subplot?

採用された回答

Walter Roberson
Walter Roberson 2011 年 6 月 17 日
How complex is your scene? The work needed for a patch or surface object is more than the work needed for line graphs.
Gerd's approach has the property of not drawing portions of the graph that would extend beyond the edges. For example if you defined a plot as a straight line between two points and you want to display the middle of that line with the end-points both outside of the window, Gerd's approach would not draw the line at all.
If you have text written on the graph that would be partly inside the sub-area, do you want the fraction of the text displayed?
The easiest approach might be to copyobj() the children of the axes to the new axes, and then set the XLim and YLim properties of the new axes to show only the portion you want.
  1 件のコメント
Gerd
Gerd 2011 年 6 月 17 日
Walter is absolutely right, I didn't think about such a scenario :-)

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

その他の回答 (1 件)

Gerd
Gerd 2011 年 6 月 17 日
Hi Daniel,
I don't know any plotting tool in Matlab but with some lines of code it shouldn't be a problem.
xlimit=get(gca,'XLim');
nearest= min(abs(a-xlimit(1)));
% find index of nearest time value
indexX1 = find(a==xlimit(1)+nearest | a==xlimit(1)-nearest);
nearest= min(abs(a-xlimit(2)));
% find index of nearest time value
indexX2 = find(a==xlimit(2)+nearest | a==xlimit(2)-nearest);
figure;
plot(a(indexX1:indexX2),b(indexX1:indexX2));
First, I would check the XLimits of the current axes and determine the nearest point in the time vector. Then plotting with the new indices. Of course you can also plot in a subplot.
Gerd

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by