Moving a slider and taking the data to calculate an output in the edit field section, appdesigner
35 views (last 30 days)
Hi everyone. I have just installed and started using appdesigner gui in matlab. I want to add 2 sliders and put the output of them in a calculation. And after that, I want to see the result inside an edit field(numeric) I have the calculations and putted the sliders, editfields , everything. The issue is, I can not take the data from slider . I watched videos and read questions but I saw that most of the explanations include some stuff I don't have in my matlab appdesigner code. I think those are related to the GUIDE section. I only have function FrequencyHzSliderValueChanged(app, event) kind of things. not handle or object names inside the designer code. I have already watched a simple calculator making video and tried to apply the same logic , I defined the variables and putted them inside the callbacks and created relations. Even after multiple ways of trying, I kept getting various errors. Any help would be appreciated.
rumin diao on 8 Sep 2022
i've added a slider and an edit field in app designer as a example,
and they will show up in the right column:
the name here is how you call them.
for example, if you want to show the current slider number in the edit field, you can add an callback function and write this in it:
% Value changed function: Slider
function SliderValueChanged(app, event)
value = app.Slider.Value;
app.EditField.Value = value;
"Value" is a property of both slider and edit field.
Ergin Sezgin on 8 Sep 2022
Edited: Ergin Sezgin on 8 Sep 2022
FrequencyHzSliderValueChanged(app, event) seems like a callback rather than a public or private function. It invokes another function or process when the slider value is changed. For your task, you need to add a function where you gather the values from the UI elements individually.
localVar_1 = app.yourComponent_1.Value;
localVar_2 = app.yourComponent_2.Value;
finValue = localVar_1 + localVar_2;
You can call the function above everytime you change the slider value using the following callback.
function FrequencyHzSliderValueChanged(app, event)
Remember that you might need to convert the data type in some cases.