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.
You can follow any comments to this entry through the RSS 2.0 feed.
You can skip to the end and leave a comment. Pinging is currently not allowed.
7 CommentsOldest to Newest
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?
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.
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:
xData = get(hPlot,'xdata');
y1 = sin(xData);
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?
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.
Excellent video. It helped me to solve a problem with a model that I was preparing. Thanks for sharing!
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.
I do not undestand your question. Please stop by https://www.mathworks.com/support.html