fetch variables from a script and use its value in a matlab app

5 次查看(过去 30 天)
Hi,
Im trying to use different variables from my script in different GUI elements in my app.
I have no idea how to do that and would be thankful if someone can help
for example I want the scoreM Variable to be displayed in an EditText field und the seperate values from the indexes of the vector would like them to be displayed seperately in other seperate EditText fields. I also would like to change the boolean variable wurfelAkzeptiert when I click a button from false to true.
Ive read that I shoud use functions to pass those variables to the GUI but I honestly have no idea how to do that. Ive been working with Matlab only for the past 2 months and now I have to programm a dice game and im finished but cant connect the logic from my code to the GUI.
Any kind of advice, short, long or excessively detailed will be much appreciated.
for j=1:3
wuVekM(j) = randi(6);
mWAuge1 = wuVekM(1);
mWAuge2 = wuVekM(2);
mWAuge3 = wuVekM(3);
sort(wuVekM);
end
if(wurfelAkzeptiert && (mDran) || wurf == 3) %durch einen Button kontrolieren
scoreM = sum(wuVekM);
  1 个评论
Jan
Jan 2019-11-28
I do not understand, what you want to achieve. The question is rather general.
The purpose of the posted code is not clear. The line sort(wuVekM); does nothing, because the sorted values are not assigned to an output. The loop fails, because wuVekM(2) is not defined which j==1:
for j=1:3
wuVekM(j) = randi(6);
mWAuge1 = wuVekM(1);
mWAuge2 = wuVekM(2);
mWAuge3 = wuVekM(3);
end

请先登录,再进行评论。

回答(1 个)

Vimal Rathod
Vimal Rathod 2019-12-5
If the script is run in the app, the variables of the script can be used in the app. The best way would be to call the script in the ‘StartupFcn’ of the app

类别

Help CenterFile Exchange 中查找有关 Debugging and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by