MATLAB error: Error Saving Figure: "Object must have an ancestor of type 'figure'" - matlab

In MATLAB 2012a,
I'm trying to save a figure as a .fig file, and all I get is a window with
Title: Error Saving Figure
Message: Object must have an ancestor of type 'figure'.
I googled this error message, and Google was able to predict my search perfectly, meaning other people have searched the same error message before .. however there is not a single page online that actually discusses this error.
I know that I haven't given much information, and I apologize for this, but I can't imagine what other details to give. 2 minutes ago I saved a different figure generated by the exact same program, in the exact same way, as a .fig file with no problems.
What does this error message mean and how do I fix the problem so that I can save figures in .fig format again ?
Edit: I am trying to save the file from the GUI.

Your problem seems to relate to how the GUI builds the figures:
* the parent object is of type 'figure'
* this object has some children of (usually) type 'axis'
* most graphical objects (lines, text, etc) belong to an axis.
It appears to go wrong with figures that have not been built the 'figure;plot(),etc...' way, eg with objects added later to the figure (eg 'legend') or plots that have been made with custom commands ('hist', 'bar3', etc).
My guess is that some GUI object has been added that does not have the figure handle as its 'ancestor'.
Queries about this problem outside StackOverflow seem to involve matlab function
"getproxyvaluefromhandle". Maybe googling that helps. Someone found help decomposing a figure here (seems to be a mix of Matlab, English and German)
If you have no code can you at least please describe what's in the figure? Otherwise the answers will be as hand-wavy as the question...

Related

Working with sample data and getting error message

I am trying to work with my data set to graph a cluster analysis similar to this example:
Why is the line of wss-plot (for optimizing the cluster analysis) looks so fluctuated?
with a previous related thread (How to draw the plot of within-cluster sum-of-squares for a cluster?)
When I follow along with the exact code of the thread (either the Iris example, or the person asking the question's example data) I get an error when attempting to plot the output:
" Error in xy.coords(x, y, xlabel, ylabel, log) : (list) object cannot be coerced to type 'double' "
The only thing I can think that is going wrong is perhaps the wrap function is not working properly. When I first attempted to do the code wrap was not recognized and so I installed the ggally package and then used the wrap function as presented in the sample codes.
Any help would be appreciated as I feel like there is some obvious and simple fix that I am missing.

Passing information back and forth between multiple figures in GUIDE GUI, Matlab

I have created several figures in Matlab (using GUIDE) which act as a config-GUI for a model. The idea is that changes made in figure F1 should affect what choices can be made in figure F2, F3, .... However, there are 5 figures, all holding different information, and it is possible to navigate arbitrarily between the figures (push buttons on each figure, to every other figure).
A large issue is that I want only one figure to be open at any point in time. That is, when F1 has started FX, I want F1 to close. Hence, I think it is unsuitable to use global variables. (?)
My issue is that I am simply not capable of holding all the data up to date. Maybe this could be achieved using appdata or guidata, but I cannot wrap my head around it.
Examples:
Since the handles of F1 and F2 differs, passing F1.handles to F2 works (F1.handles shows up in varargin{1} in F2), but I cannot concatenate F1.handles with F2.handles. Hence, I have no apt way of sending F1.handles and F2.handles to F3 (or any other figure). (If this can be achieved in a more simple way, I might be okay with dropping the "arbitrarily navigation feature", but so far I have not been able to make it work.)
Using .mat-files (i.e., write FX.handles to a file and load each file in each Figure) seems such bad practice that I haven't even given it a serious go.
So far, I have not found it necessary to change the data in FN±X from FN, hence I guess the .mat-file approach could work, but my latest idea is using Matlab OOP and pass around a class instead of the handles. I found an old post on the topic (Global (shared) variables in Matlab GUI code behind. Is there better way to do it then using handles structure?) but it links merely to a File Exchange and I am unable to understand how to make it applicable for my use case.
Edit 1: I found this Using GUIDE with object-oriented MATLAB?, and will give it a try, but I am still having a hard time understanding exactly how to use it, since it seems to require using handles anyway.
U can try using global variables to retrieve handles for all the figures created by assigning handles values to a global variable in a structure format. Global variable persists in memory until you close the figures.

Matlab GUI, sometimes listbox disappears. I used: set(handles.listbox,'value',1) and seems it does not work

In the GUI, I have two listboxes, and the data in these two listboxes can be passed to each other. A user can pass all the data to the other one, he can also select some data and pass to the other one.
The problem is: Sometime, the listbox will disappear, but all the pushbuttons works as expected. And Matlab gives a warning: Warning: multi-selection listbox control
requires that Value be an integer within String range.Control will not be rendered until all of its parameter values are valid.
I did some research, someone advises to use this: set(handles.listbox,'value',1) . But it does not solve this problem.
And what's more, I cannot figure out under what kind of circumstance this error may happen.
Can you guys please tell me how to solve this? And in which case this error may happen?
Thanks a lot.

How to pass between guis in matlab

I am doing a group project and we are supposed to be using GUIS to create a presentation. In the presentation there is data that is loaded in using an edit text box and our code then goes through calculations and if statements and is supposed to pass certain values to a different GUI. Our instructors do not know how to do it because we have asked them on several occasions and they cannot figure it out. We have tried varargin method and the getappdata method and neither one is working. Does anyone have suggestions? PLEEAASE!!
I would write some "Controller" program that will know open the figures for you and know how to forward the data. Basically it would be a simplified mvc-pattern. It could also assure the figures are opened in correct order.

Using matlab code in Octave - Bayes Net Toolbox

I am trying to run Kevin Murphy's Bayes Net Toolbox in Octave and encountering some problems. It doesn't help that I'm a novice at Bayesian networks, Matlab and Octave.
This toolbox was originally written for Matlab. There is a large test file called test_BNT.m which runs through all the functionality in the toolbox. Most of the error messages relate to the difference between & and && in Matlab and Octave. This is easy to fix. However, I've now come across a new problem and I don't know what to do about it.
For instance, the qmr1.m script creates an instance of the pearl_inf_engine class, sets some of the member member variables and passes the instance of the class to another function. Later on, the member variables are accessed again in a different script (parallel_protocol.m). But when this happens, the following message appears:
error: invalid index for class
error: evaluating argument list element number 1
It seems that from one script to another, it has forgotten that the class has any member variables and gives the invalid index message when you try to access them.
Is this a common error with an easy solution? Is something wrong with the path or working directory? Maybe someone else has already converted the BNT to octave and knows what to do?
Edit
I was able to get past this error message. The trick was to read the installation instructions (haha) and run addpath(genpathKPM(<BNT base directory)). genpathKPM.m is a script includes in BNT which adds all the required directories to the path.
After doing this, run test_BNT.m and change & to && and | to || at each line where it gives a warning. This will clear up most of the errors.
However, I'm still unable to run mpe1.m, mp2.m, mildew1.m and some others. The new error message I'm stuck on is:
error: invalid empty index list
error: called from:
error: C:\FullBNT-1.0.7\bnt\BNT\inference\static\#var_elim_inf_engine\find_mpe
.m at line 63, column 5
on this line of code:
eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);
If I can get all the scripts to work, I'll post an answer here with the steps I took to do it.
Edit 2
I was able to get past the problem in the previous edit. Replace
eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);
with
eval(['sCPT.T(', sargs, sprintf('%d',jj), ')=0;']);
The next problem is identical. Just replace num2str in the same way.
This file was apparently contributed by a user of BNT, and not written by the original author. Using eval kind of a hack, I think. A better fix would be to just rewrite the code so it doesn't use eval at all.
There is one more error in draw_graph.m, which was apparently also an outside contribution to the project. I just commented out the call to that function since I'm not interested in drawing graphs right now. After doing this, and continuing to fix shortcircuit operators, all of the tests in test_BNT.m will run.
Still, I won't create an answer for this until I can get draw_graph.m to run, too.
As a significant amount of time has passed, and the answer to the core problem was provided in the question, I will post it here so it will not stay listed as unanswered:
tl;dr: Change a few operators, solve the remaining bugs specified below, and everything works except the drawing of graphs.
Edit
I was able to get past this error message. The trick was to read the
installation instructions (haha) and run addpath(genpathKPM(<BNT base
directory)). genpathKPM.m is a script includes in BNT which adds
all the required directories to the path.
After doing this, run test_BNT.m and change & to && and | to
|| at each line where it gives a warning. This will clear up most of
the errors.
However, I'm still unable to run mpe1.m, mp2.m, mildew1.m and
some others. The new error message I'm stuck on is:
error: invalid empty index list
error: called from:
error: C:\FullBNT-1.0.7\bnt\BNT\inference\static\#var_elim_inf_engine\find_mpe
.m at line 63, column 5
on this line of code:
eval(['sCPT.T(', sargs, num2str(jj), ')=0;']);
If I can get all the scripts to work, I'll post an answer here with
the steps I took to do it.
Edit 2
I was able to get past the problem in the previous edit. Replace
eval(['sCPT.T(', sargs, num2str(jj), ')=0;']); with
eval(['sCPT.T(', sargs, sprintf('%d',jj), ')=0;']);
The next problem is identical. Just replace num2str in the same way.
This file was apparently contributed by a user of BNT, and not written
by the original author. Using eval kind of a hack, I think. A better
fix would be to just rewrite the code so it doesn't use eval at all.
There is one more error in draw_graph.m, which was apparently also
an outside contribution to the project. I just commented out the call
to that function since I'm not interested in drawing graphs right now.
After doing this, and continuing to fix shortcircuit operators, all of
the tests in test_BNT.m will run.