Effacer les filtres
Effacer les filtres

plot in predesigned figure

180 vues (au cours des 30 derniers jours)
Josefina Ottitsch
Josefina Ottitsch le 19 Fév 2019
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 commentaire
dpb
dpb le 19 Fév 2019
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.

Connectez-vous pour commenter.

Réponse acceptée

Kevin Phung
Kevin Phung le 19 Fév 2019
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 commentaires
Walter Roberson
Walter Roberson le 19 Fév 2019
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 le 21 Fév 2019
Thank you! It works better now!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by