MATLAB Automate GUI - matlab

I currently have a GUI that outputs a single text file based on various input parameters. However, I need to modify my application such that the GUI outputs multiple text files based on N inputs. The original GUI designer is no longer available and the main m-file has over 5k lines of code making it difficult to troubleshoot (not to mention the code is very unorganized and not commented). Does anyone have any suggestions on how I can run the GUI N times based on the N inputs and output N text files without modifying the original m-file?

Assume your gui is called myApp and your callback to s called myButton_Callback.
I also assumng that the tag of the uicontrol is 'myButton'.
Here is the caller script:
myApp_h = myApp();
myApp_handles = guidata(myApp_h);
myButton_h = myApp_handles.myButton;
MyApp('myButton_Callback', myButton_h, myApp_handles);
You can automate any gui control by this method.

Related

Matlab - replace classification layer using a script (automatically)

i want to train a neural network with flexible output size. In the beginning, i used the matlab deep network designer to manually replace the classification and fully connected layer to the desired output size. Now, i want to automatically replace it, using a script.
Which command is working for that?
Simply trying the line:
net.Layers(142,1).InputSize = 10;
gives me the error message
Unable to set the 'InputSize' property of class 'FullyConnectedLayer' because it is read-only.
Trying to replace the complete layer (not only inputsize) is resulting in the same error message.
Is this possible with matlab, and if yes, which commands will do the job?
Thanks in advance!
Okay, i think i solved it. When changing the network manually inside of the deepnetworkdesigner, there is the possibility to click "export code" which exports the desired code for the adapted output size

How can I close the report window after code generation using rtwbuild() for a Simulink model from the command line?

I'm trying to automate the building process of my Simulink models. I achieve to handle the configuration of these models as I want.
Then I start generation using the command :
rtwbuild('system', 'Mode', 'ExportFunctionCalls');
That's working pretty well. At the end of the generation, a window appears showing a report of the generation allowing me to browse the just generated code.
My script builds several models and I would like to close this window after each model generation in order to don't disturb the user with all those reports "poping out".
An even better solution would be to not even show this window. I don't need to see it in my generation process and I don't want the user to click the OK button for each report.
So, is there a way to prevent rtwbuild() command to show this report when it's done ? Or at least, is there a way to close this window from the command line after the generation ?
As suggested by #Navan in the comments, there is a model parameter for that.
So to disable the generation of the report (and therefore the opening of the report window), you can simply use the command :
set_param(system, 'GenerateReport', 'Off')
I also got some more information from the MATLAB support. It is also possible to generate this report but prevent the window from opening using these commands :
set_param(system, 'GenerateReport', 'On')
set_param(system, 'LaunchReport', 'Off')
I was using MATLAB R2011a. But since R2012, there are some dedicated methods to open/close code report :
coder.report.open
coder.report.close()

How to link a Matlab gui to a .m file?

I have a .m file that contains this lines
%reading 2 images
image1=imread('pic1.tif');
image2=imread('pic2.tif');
% two varialbes
number_of_points = 100;
simpling = 30;
I want a simple gui with matlab that allow the user to :
select the 2 images by opening a pop-up window to explore the files on the pc.
choose a value for the two variables "number_of_points" and "simpling" using radio buttons 100,150 or 200 for the first and 0 or 30 for the second.
I created a gui with matlab but I can't find a way to add those functions.
this is what it looks like :
http://s9.postimg.org/k6ed9pni7/stack.png
How can I make the gui execute my .m file with those parameters ?
I'm a newbie so any help will be appreciated.
One solution is to turn your m-file into a function that takes the four parameters as input. Than you can call your function from your Lancer button callback.
The alternative is to assign the values of your edit boxes & radio buttons to a variable in the base workspace and run your m-file as a script from the button's callback. If you prefer this method, you can assign variables from the GUI's functions in the base workspace (where your script will run) via evalin('base','expression')
Here,'expression' would be something like sprintf('myPic1 = %s; myPic2 = %s; number_of_points = %d; simpling = %d;', handles.myEdit1.String, handles.myEdit2.String, handles.myRadios1.Value, handles.myRadios2.Value);

MATLAB GUI - How do I control actions in one window from another window?

I have a GUI that displays plots, and it launches a "playlist" window. When I perform an action in the playlist window, is there a way to run a function in the launching window?
To be more clear, if I add files in the playlist window, I would like the first file in the list to be displayed in the launching window, but I would like to do this through a function in the launching window rather than passing the plot handle to the playlist window.
Thank you in advance for any assistance you can offer!
One of the easiest ways to do this, would be using findobj.
This looks through graphics objects, finding those that match the provided filter criteria.
As the number of existing figures should be relatively small, it should also be reasonably fast.
Assuming your launcher-figure has some name you can get the launcher figure-handle
e.g. via
launcherFig = findobj(0,'type','figure', 'name', <launcher-name>);
Or give your lauchner figure a Tag that you can search for:
% in your launcher-figure code:
launcherFig = figure('Tag', 'MyLauncher');
% and modify the search accordingly:
launcherFig = findobj(0, 'type', 'figure', 'Tag', 'MyLauncher');
And, for completeness, though I don't like them, you could use a global variable:
% in your launcher-figure code:
launcherFig = figure(...);
% store handle in the global variable:
global LauncherHandle;
LauncherHandle = launcherFig;
% no need for a search now anymore, just get the global variable:
global LauncherHandle

relation between main GUI's and sub GUI's

I have two GUIs namesd masir and SetOut
SetOut GUI is a sub GUI for masir(pressing a button on masir will open SetOut)
To access the data of masir in SetOut I have these 2 lines of code:
masirGUIhandle = masir;
masirGUIdata = guidata(masirGUIhandle);
but running these 2 lines will run the opening function of masir as I work in SetOut(In opening function I have set some initial values for my variables and now I don't want those initial values ,I need changed values for my variables) so I dont want the OpeningFcn of masir GUI to be runned ,I just need to have access to masir data in SetOut
What can I do to fix the problem?
Can any one help me about this answer and explain me more?
I use this easy way for data sharing between GUIs
%In the end of OpeningFcn of Main GUI
setappdata(0,'HandleMainGUI',hObject);
%When you want to edit shared data you must get the handle
HandleMainGUI=getappdata(0,'HandleMainGUI');
%write a local variable called MyData to SharedData, any type of data
setappdata(HandleMainGUI,'SharedData',MyData);
%get SharedData and save it to a local variable called SomeDataShared
SomeDataShared=getappdata(HandleMainGUI,'SharedData');
Don't forget to clean up the data shared in the CloseReqFcn of you main GUI
HandleMainGUI=getappdata(0,'HandleMainGUI');
rmappdata(HandleMainGUI,'MySharedData') %do rmappdata for all data shared
Remember that your GUIs might try to getappdata that doesn't exist, you should first test if it does exist
if (isappdata(0,'HandleMainGUI') & isappdata(HandleMainGUI,'MySharedData'))
%get, set or rm appdata
else
%do something else, maybe loading default values into those variables
end
Tell me more aboute which line of code should be written in MainGUI and which line should be written in SubGUI?
And tell me what does the responser mean by CloseReqFcn?
Well let me summarize how I see the problem.
You want to read the data from SetOut with out creating it? That's not possible like this as the data will be created when the window is created.
A nice and systematic way around would be doing it object oriented (see Model-View Controller Pattern) You can more or less copy an example from my answer here (Example for Event - Observer)
But if you'd like to stick with your code I also have some ideas:
If you don't want the window to show you could set it invisible with set(theGUIhandle,'Visible','off')
While the window is not closed you can obtain the data with getappdata(theGUIhandle)
If you want the data after the window is closed you need to have a function that stores it outside the window.