Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the Original version of the page.

Adding UICONTROLS to MATLAB without GUIDE for simple interactive figures 7

Posted by Doug Hull,

There are often small tweaks to functionality that you would like for a figure in MATLAB. This video shows how to add a button to a figure that will allow you to toggle the units of a y axes between inches and centimeters.

7 CommentsOldest to Newest

Nikhil replied on : 1 of 7
hi, im working on code in which i want to place the pushbutton or popup menu vertical, instead of it being horizontal as shown. The text on the button/popup menu be displayed vertically. Is it possible to do that?.. if so how?
Doug replied on : 2 of 7
Not really, you can make an image of the rotated text and put that on the button. There are similar functions on the file exchange.
Adrienne replied on : 3 of 7
I modified this code to try out a pop-up menu in which the user decides which of four functions (sin,cos,x,x^2) will be plotted. My primary function is plotFunctions, with a subfunction changeFunction that uses switch case. To make it work, I had to do this inside each case in changeFunction: case 1 xData = get(hPlot,'xdata'); y1 = sin(xData); set(hPlot,'ydata',y1,'color','b','LineStyle','-'); ylabel('y = sin(x)'); Initially, I had defined the x and y data for each of the functions before changeFunctions, but changeFunctions didn't seem to see it so I had to put it inside. Why didn't my subfunction recognize the data I had created earlier in the file?
Doug replied on : 4 of 7
@Adrienne, These are just subfunctions. They follow all the same rules of scoping that other functions follow. Data from one function does not make it into other functions unless explicitly passed. Doug
Claudio Gelmi replied on : 5 of 7
Excellent video. It helped me to solve a problem with a model that I was preparing. Thanks for sharing!
Daniel replied on : 6 of 7
Hello, How can I have a x-axis of my own? If I have y=[1 2 3] and x=[10 20 30]; I want to just convert y but still plot vs my x. I have copied your code it only converts to CM once and then it converts with a offset that ads everytime when I click convert... and it only says CM on the y-axis.
Doug replied on : 7 of 7
@Daniel, I do not undestand your question. Please stop by https://www.mathworks.com/support.html Thanks, doug