MATLAB Answers

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

1 view (last 30 days)
Muhialdeen Ibrahim
Muhialdeen Ibrahim on 27 Nov 2019
Answered: Vimal Rathod on 5 Dec 2019
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 Comment

Jan
Jan on 28 Nov 2019
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

Sign in to comment.

Answers (1)

Vimal Rathod
Vimal Rathod on 5 Dec 2019
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

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by