Can someone help me?
Access ui edit field values and sharing them in different functions
7 views (last 30 days)
Show older comments
Hello everyone, i'm quite new to MATLAB and for my thesis project I am creating a program that allows you to simulate a cut on a stl file of a tibia, reshape the polygons and plot the new modified image when pushing a button.
The parameters needed to be entered are 4: height, posterior angle, lateral angle and rotation of the prosthesis.
Now I am creating the graphical interface and I have decided to assign each input to a numericField.
I have created a function to generate all the buttons and their callbacks, while I have another function where the calculations are performed.
The problem I am having is that of not being able to access the value inserted in the numeric field and to assign it to a variable that can be shared in several different functions in the same .m file.
I tried to use global variables but I ran into problems.
Thanks everyone in advance for the help, I am attaching my file with the functions.
3 Comments
Matt
on 21 Oct 2022
I think you need to use setappdata and getappdata.
For exemple you want to share the height value between your functions. First you use settappdata to create the height value and store it in your figure object (called fig1 in your code)
height_ini = 1;
setappdata(fig1,'height',height_ini);
Then you want to update this value when the user update the height field.
So you in the callback function you use setappdata again to update the value :
function numberChanged(NF_height,event)
valore = NF_height.Value;
setappdata(NF_height.Parent,'height',valore)
end
And finally you get the data when needed (in your calc function I guess) with
height = getappdata(obj,'height'); % where the variable obj is fig1 : the place where the data is stored in my exemple
Answers (1)
Cris LaPierre
on 21 Oct 2022
Edited: Cris LaPierre
on 21 Oct 2022
I would suggest developing your app in app designer. Once there, see this page on how to share data within your app.
2 Comments
Cris LaPierre
on 24 Oct 2022
That is how I started building my apps, too. I have a couple suggestions. First, try to complete the built-in tutorial. Then, consider taking a look at the last chapter of MATLAB Essentials on edX, which covers building an app. You can enroll for free.
See Also
Categories
Find more on Develop uifigure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!