USING GUIDE
By Sahil Potnis, VIT, Mumbai
Creating a GUI in Matlab
TUTORIAL : 2
Expected Outcomes:
By Sahil Potnis, VIT, Mumbai
This presentation will âguideâ you to â
Guide stands for GUI Development Environment.
Create a new GUI on your own.
Plot graphs in it and save them.
By Sahil Potnis, VIT, Mumbai
Step 1:
Create new GUI by using standard default template available.
Select (UIControls) template, the one described in previous tutorial.
Save it with a title â Linear_equationâ, this will generate a linear_equation.m file.
Do not alter the .m code up to line no:74 .
By Sahil Potnis, VIT, Mumbai
Create New GUI
By Sahil Potnis, VIT, Mumbai
Make two variables âXâ and âYâ and correlate them using any linear equation. Find value of âYâ when âXâ is given.
Add a graph by selecting axes and another pushbutton for plotting y vs x.
For ex: 5X=4Y + 50. Let user enter the value of X and find value of Y
after pressing calculate.Make sure you enter the formula within callback of
âcalculateâ to find value of âyâ.Remove unnecessary objects within the code and
check for all tags and handle variables..!
STEP 2:
By Sahil Potnis, VIT, Mumbai
An ideal GUI figure should look like this:
STEP 3:
By Sahil Potnis, VIT, Mumbai
Within callback of âPlotâ button write the code for simple plotting of two variables. Write â
axes(handles.graph); % graph is tag for axes object% Start your code CODE% End your code
This should generate the Plot when you click on Plot.
Hint- Create a function for the plot & call that function in you code for complex equations.!
By Sahil Potnis, VIT, Mumbai
Checkpoint 1:
By now you should be ready with â
A GUI that calculates and resets the values of y and x respectively based on your entered equation.
Plots the graph in the space for âgraphâ when âPlotâ is clicked.
By Sahil Potnis, VIT, Mumbai
Step 4:
Now, go to the Menu editor option, present in the toolbar on top of your .fig window.
Create a âContext Menuâ and add a new context menu âsave asâ.
Now go to Property Inspector of the âgraphâ and in the option âUIContext Menuâ select your option and deselect ânoneâ.
Save the fileâĶ.
By Sahil Potnis, VIT, Mumbai
By Sahil Potnis, VIT, Mumbai
By Sahil Potnis, VIT, Mumbai
Once done, within the callback of âsaveasâ paste this code â
f = figure;copyobj(handles.graph,f); %graph is a tag for axesFileName = uiputfile('*.jpg','Save as'); saveas(f,FileName);
You can alter the file format as required..Now, when you run your GUI you can save the
graph by right clicking it..!
By Sahil Potnis, VIT, Mumbai
Checkpoint 2:
You are ready with completely functional GUI.
It has options for computing a linear equation.
Plotting a graph.
Saving the graph by âright clickingâ on graph.
By Sahil Potnis, VIT, Mumbai
Keep on trying new things.....Its the best way to
learn.!!
Watch out this space for more tutorials on Matlab....
Thank You
By Sahil Potnis, VIT, Mumbai
For further advanced Matlab programming visit : http://sahilpotnis.blogspot.in/
Or drop me a mail at : [email protected]