Hello
I have a script, where I tell my programm to create a figure, called h ,looking like the second picture.
then in a function within the scirpt (1. picture) i want matlab to draw my desired plot into the predesigned figure h. (See function in 4. picture)
but instead, matlab doesnt draw my plot into h, matlab draws it as in the 3. picture.
How do i plot into my predesigned figure h?
Thanks for the help!

1 件のコメント

dpb
dpb 2019 年 2 月 19 日
Give us the actual text to read instead of trying to look at pictures of it...
In general, to plot to a given figure/axes, you call plot() with the specific axes handle you wish to plot into...otherwise, by default it will use gca or create a new one if none are extant.

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

 採用された回答

Kevin Phung
Kevin Phung 2019 年 2 月 19 日

0 投票

You can assign a handle to the axes of the figure, and reference them in your plot function.
for example:
fig1 = figure;
a = axes;
fig2 = figure;
a2 = axes;
%plot in axes in fig1:
plot(a,1:5,1:5)
%plot in axes in fig 2
plot(a2,1:5,1:5)

4 件のコメント

Josefina Ottitsch
Josefina Ottitsch 2019 年 2 月 19 日
thank you for your answer!:)
However, in h i have programmed a complete detailed figure with grid and line width and everything.
and i want to put my graph directly into this preprogrammed figure. But it isnt working properly. Matlab is telling me:error using plot line cannot be a child of figure
Kevin Phung
Kevin Phung 2019 年 2 月 19 日
the first argument in plot needs to be the handle to your axes, not the figure.
you can search for the axes by doing:
get(h,'Children')
if this returns an array of multiple graphics objects, then just use indexing to grab the axes and assign a handle to it, otherwise, get(h,'Children') would just show your axes and you can assign a handle to that.
Walter Roberson
Walter Roberson 2019 年 2 月 19 日
ax = findobj(h, 'type', 'axes');
if isempty(ax)
error('Your figure does not have any existing axes')
end
if length(ax) > 1
error('Your figure has more than one axes')
end
plot(ax, [line1.x], [line1.y]
An alternative for that last line would be
plot([line1.x], [line1.y], 'Parent', ax)
Josefina Ottitsch
Josefina Ottitsch 2019 年 2 月 21 日
Thank you! It works better now!!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by