Matlab GUI Attempt to reference field of non-structure array - matlab-guide

I have a GUI menu on Matlab with 4 buttons (menu.fig). Then I have 4 .fig file that I want to open when I click on the buttons. Here it's all ok, when I open a .fig from menu and insert value to do a plot I get this error:
???? Attempt to reference field of non-structure array.
If I try to open 1.fig directly, everything works perfectly.
I read that the problem is with eval(), but I can't solve it.
I changed the variable names on each .fig file
One 1.fig:
function pbutton1_Callback(hObject, eventdata, handles)
A1=get(handles.edtSAmp,'String');
f1=get(handles.edtSFreq, 'String');
fi1=get(handles.edtSFase, 'String');
t1=get(handles.popTipo, 'Value');
A1=str2double(A1);
f1=str2double(f1);
fi=str2double(fi1);
SinalSinusoidal(A1,f1,fi,t1);
I got the error on the that 1st line.

I guess this is something MATLAB GUI not handled well. I know it used to work, but when you tweaking your UI or UI related code a bit and accidentally you modified some area MATLAB told you not to touch, this kind of issue begin to happen.
The workaournd is to start the GUI from M editor by clicking run
I know it works, but originally, when I directly lauch it , it works too. so, this is not the end of it, people are just not getting to the end of it.

The problem is with probably with handles1. It's not a structure array like you expect it to be. In GUI's created with GUIDE, this variable is usually called handles, if you have both handles and handles1 make sure handles1 contains handles to the objects in the figure. If you're using handles1 only, make sure you're initializing it properly.

Related

UNbound Text Box wont save

I have a form onto which I have placed an unbound text box. This box is designed to calculate the total of 4 other bound text boxes which have simple numerical values in. I have used the expression builder in the unbound text box to set its control source property i.e. =([box1]+[box2]+[box3]+[box4])
When I first put this in it works fine. However after I close and then reopen the data base the box sits on the form saying #NAME? as if it has lost its control source. I have checked the data source after and nothing seems to be wrong. Any ideas why its happening. Its a pain as I have a button which when pressed opens a report based on the value in the unbound text box.
Try using Nz:
=Nz([box1],0)+Nz([box2],0)+Nz([box3],0)+Nz([box4],0)
Not entirely sure why it now works but I have re added the text box and the calculations into the source code and it seems to be fine. Perhaps just a glitch in my previous attempt... I used the =sum solution rather than the =Nz solution. Maybe my version of access or my data base is just fickle... thanks anyway

Matlab GUI gives error, but m file okaz

I`m absolutely new in Matlab, so I think it is a dumb question, but I would be really grateful for any help.
I had made a GUI with some slider. When I compile the m file everything works fine, there are no exceptions and the program do what it have to, but when I click on the fig file directly and try to move one of the sliders I got the following error:
??? Undefined function or method 'diference_GUI' for input arguments of type 'char'.
Error in ==>#(hObject,eventdata)diference_GUI('slider1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I had found some forum, blog article in this topic, but I want able to solve. Try-Catch not good, because if I do it, I dont get any error message, but the program still don`t do what it need.
Thank you for your help, Karoly
Your question isn't quite clear, but I'm assuming that you've made a GUI called difference_GUI using GUIDE in MATLAB.
When you do this, you'll get two files, difference_GUI.m and difference_GUI.fig. At that point, you should basically leave difference_GUI.fig alone, without opening or modifying it. Start the GUI by typing difference_GUI, which will run the .m file, which uses the information in the .fig file to lay out the GUI.
If you need to modify the layout of a GUI that you've created in GUIDE, you can open the project again in GUIDE and make minor modifications to it, such as repositioning a slider - but if you need to make major changes to it, I personally find it easier to copy the algorithmic portion out of the .m file, create an entirely new project, relaid out, from scratch, and then paste the algorithmic portion back in to the new .m file.

Matlab GUI's managebuttons

I have to maintain a large MATLAB GUI, containing quite a few callback functions, each of which gets called at many points. At some point, I decided to rename one of the callbacks; in order not to have to go through GUIDE to manually modify each of the UI that calls it, I used the excellent gencode program to "unwrap" the .fig file, s/old_name/new_name/g, and recreate the .fig.
This seems to work well, except for one thing: when clicking on a button in a button group, I got a message telling me that the function manageButtons is unknown. After a bit of googling, I find that manageButtons is a nested function in childAddedCbk, which, I assume, is called by GUIDE as the GUI is created. Now, trying to move just manageButtons outside to its own, in-the-path file doesn't work either: the hgroup passed to it is an invalid handle object.
So... does anyone has a workaround for that? Any of the following will be appreciated:
changing all the callbacks in a GUI in a semi-automatic way, or
making the manageButtons get a valid handle, or
having gencode not break all that.
Thanks,
Antony
You can export the FIG + M file to single .m file. You will lose the ability to edit this with guide, but you will be able to do a simple regular expression replace on the resulting .m file.
In order to do so - use on the menu of GUIDE -> File -> Export.

MATLAB: Prevent figures from being made active

I have a rather large routine which will can run for a couple of hours. Here and there it creates a figure, plots something to it and saves that Figure.
As I have only one PC, I would like to continue to work with that machine. The problem is that whenever a new figure is made, MATLAB becomes the active application again.
Is there any way to tell MATLAB or Windows that MATLAB should not be allowed to set itself to active?
I saw that one possibility is to run a MATLAB script totally in the background (like that). But that is a little bit too unsupervised, as I would like to be able to switch to the MATLAB window and check the output to the command window.
Any ideas? If there is a general solution for Windows that prevents that other Applications to become active would also be cool!
You can overload the figure function as following in order to prevent figure poping up:
a = figure('visible','off');
I hate to state the obvious, but you could always store the data you want to plot until the end.
Now, you're going to tell me that some of that data is subroutines and doesn't get passed back to the main routine. OK. So, the solution to that would be to write a "Store_Plot_Data" class with a method that would write into memory the data, the #plot_function_name (for 3D, scatter, etc.), the axis label strings, etc. Then you would create one instance of this class in your main routine and to ensure visibility of this one instance to all subroutines you could do any of the following:
use a global variable as your single instance ... OK, not so elegant,
implement the Singleton pattern, or
pass all subroutines the handle to that one instance of the "Store_Plot_Data" class.
If there is a general solution for Windows that prevents that other
Applications to become active would also be cool!
In Windows 7, this worked for me:
http://pcsupport.about.com/od/windowsxp/ht/stealingfocus02.htm
Set "HKEY_CURRENT_USER\Control Panel\Desktop\ForegroundLockTimeout" to 30d40 (hex).
If you want all figures to not show.
set(0,'defaultFigureVisible','off');
In the beginning of your script do:
set(0, 'DefaultFigureVisible', 'off');
set(0, 'DefaultFigureWindowStyle', 'docked');
Dock the Matlab figure window and maximize any other application (Excel, Word etc.) you are working with in front of Matlab.
Then you can continue to work without being interrupted by figures blinking on your face.

Changing multiple .fig files in Matlab systematically

I want to browse a directory where many Matlab GUI's (.fig files and their related .m files) are stored and change them systematically. For each, I want to search for a certain popup menu and, if it exists, delete some specific options.
I usually use get() and set() or similar functions to fiddle with GUI's, but these functions require handles, and I don't know how to get handles when not running the GUI, and also I wouldn't know how to save the changes.
If I open a .fig as text it is unintelligible.
I'm considering opening each at a time in guide (Matlab's GUI development environment) and changing it manually, but really would like to avoid it. I'm talking about tens of files, and my action might have to change in the future.
Maybe there would be a way to control guide from the command line? Or another solution?
You can load the .fig files using hgload or openfig. Both these functions return the figure's handle.
Once you have the figure's handle you can use findobj to get the popup menu's handle. Then set and get as normal to change the menu's options, and then save the modified figure using hgsave.
For example:
f = hgload('file.fig');
menuH = findobj(f, 'Type', 'popup');
set(menuH, 'String', new_options);
hgsave(f, 'file.fig');
gcf() immediately after open() gets the handles and can be done programatically for many figures.

Resources