GUI in Matlab - 2

Post on 07-May-2015

834 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Second Tutorial for learning the basics of Matlab GUI programming....

Transcript

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 : sahil.potnis@vit.edu.in

top related