Effacer les filtres
Effacer les filtres

Displaying an externally saved figure in live script

8 vues (au cours des 30 derniers jours)
Abed Alnaif
Abed Alnaif le 21 Juin 2019
Modifié(e) : Lucian le 24 Mai 2023
Hello,
I'm trying to display an externally generated figure in live script, using the openfig() function. When I do this, the figure does not display; all that displays is some output text listing some properties of the figure. Is there a way to display externally generated figures, .fig or otherwise, in live script?
Thanks,
Abed

Réponses (1)

Alex Zak
Alex Zak le 11 Mar 2020
Hi Abed,
Currently openfig is not fully supported in the Live Editor. As a workaround you can do the following:
f = openfig('f.fig');
f2 = figure;
set(f.Children,'Parent',f2)
This should dispaly the contents of the saved figure in the Live Editor.
Thanks,
Alex
  3 commentaires
pablo Jaramillo
pablo Jaramillo le 4 Nov 2020
This worked, though I had this error for the legend:
Error using matlab.graphics.illustration.Legend/setParentImpl
A legend and its associated axes must have the same parent.
Lucian
Lucian le 24 Mai 2023
Modifié(e) : Lucian le 24 Mai 2023
Hi all,
Thanks for sharing.
After a lot of grey hairs with Matlab R2018b a small adaption is needed to the code:
f = openfig('f.fig');
f2 = figure;
set(f.Children(2),'Parent',f2)
Adding the index 2 solves in some cases the error (axes is the 2nd element in an array)
"Error using matlab.graphics.illustration.Legend/setParentImpl
A legend and its associated axes must have the same parent"
I can also confirm that this error does not appear with Matlab R2021b
Cheers,
Lucian

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks 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