How to start a script in App designer and update a variable with slider ?

조회 수: 15 (최근 30일)
Raed Wasseghi
Raed Wasseghi 2020년 10월 7일
답변: Nitin Kapgate 2020년 11월 3일
Hey everyone,
I have read through the forum, watched youtube videos and read the "help ...." explanations in matlab, but Im just getting more confused. I hope to find some helpful advices here.
First, I would like to run a script through appdesigner, so that the workspace is filled with the variables and I can use them, for instance with "evalin(...)" command. However, many comments suggest to use "run SCRIPTNAME" or run("SCRIPTNAME"), but it does no fill the workspace with the variables. I put this in the startupFcn(app), but it didn't show the results I need.
Is it possible? Or do you always have to run the script separately ? I also tried to do the other way around and let the script run my app designer program, but im not really satisfied with this approach.
Second, lets say the Script generates a random Matrix with M=randi([a 200], 5, 5) and I would like to adapt variable a with the slider. I am not sure how to do that, my current approach is in the button callback function:
function StartButtonPushed(app, event)
Matrix = evalin("base", "M");
Aslider = app.Slider.Value;
assignin("base", "a", "Aslider");
run myscript.m;
app.UITable.Data = Matrix;
This is what I got out of the many answers I read, but the slider doesn't work. I'm sure the slider needs to be programmed differently, but the examples from matlab dont show the connection with the variables from the script. Thanks in advance!

답변 (1개)

Nitin Kapgate
Nitin Kapgate 2020년 11월 3일
It’s not recommended to use variables from base workspace in App Designer Apps as base workspace variables could get modified by other MATLAB scripts.
It is recommended to use properties in App Designer and create App’s own workspace. You can declare different properties (parameters/variables) that can be used by the app by adding private/public properties in the Code-View in App Designer. These properties can then be initialized in startupFcn and used/modified in different Callback functions. These properties can be used across the app to achieve the desired functionality. These properties can be referred with the syntax appName.PropertyName.
Refer to the MysliderSliderValueChanged slider callback function in the attached appSlider app that demonstrates the use of slider to change a parameter’s value. You can run the app and try changing the slider value.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by