Moving a slider and taking the data to calculate an output in the edit field section, appdesigner
38 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
rumin diao
2022 年 9 月 8 日
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;
end
"Value" is a property of both slider and edit field.
1 件のコメント
Ergin Sezgin
2022 年 9 月 8 日
編集済み: Ergin Sezgin
2022 年 9 月 8 日
Hello Fatma,
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.
function calculateFinValue(app)
localVar_1 = app.yourComponent_1.Value;
localVar_2 = app.yourComponent_2.Value;
finValue = localVar_1 + localVar_2;
end
You can call the function above everytime you change the slider value using the following callback.
function FrequencyHzSliderValueChanged(app, event)
calculateFinValue(app)
end
Remember that you might need to convert the data type in some cases.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!