save variables in Matlab GUI

hello;
if I want to save some constant
x=100;
y= 200;
how I save them in the Matlab GUI code as seen below

답변 (1개)

Rik
Rik 2022년 3월 9일

0 개 추천

For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.
With your current setup you can store them in the guidata:
handles.x=100;
handles.y=200;
guidata(handles.figure,handles)

댓글 수: 10

Huda M
Huda M 2022년 3월 9일
편집: Huda M 2022년 3월 9일
okay,
If I want the user to enter text such as; x or y in the inputs after running the program what should I do?
Something like this you mean?
handles.x=a0;
handles.y=a1;
Huda M
Huda M 2022년 3월 9일
no I mean in input a0 the user will enter x
and in input a1 the user will enter y
Rik
Rik 2022년 3월 9일
I don't see how that is different from the code I showed. If you mean the user typed in the letter x instead of a value, then str2double also wouldn't work. You can of course store a char array in a variable. Is that what you mean?
Huda M
Huda M 2022년 3월 10일
편집: Huda M 2022년 3월 10일
if the input is text such as x or y what should I use instead of str2double?
Rik
Rik 2022년 3월 10일
That depends. Is your goal to store it as text? Or do you want to convert it to symbolic variables?
Huda M
Huda M 2022년 3월 10일
편집: Huda M 2022년 3월 10일
I want the user to enter letters but this letter equal to a number
for example a=5 which is saved
then as the user enter a in the input box
Matlab knows it is 5
Rik
Rik 2022년 3월 10일
Then your actual question isn't about how to store variables in a GUI, but how to match user input text to a variable.
How are you storing those variables? This seems like a design waithing for trouble. It sounds like it will be very easy to break things this way, especially if you are going to make the mistake of using eval to solve this.
Huda M
Huda M 2022년 3월 10일
so is it impossible to do it?
Stephen23
Stephen23 2022년 3월 10일
편집: Stephen23 2022년 3월 10일
"so is it impossible to do it?"
I doubt that it would be impossible, but it is unlikely to be good data design or good code.
Accessing the property of a class or field of structure would be simpler. Or perhaps a basic array...
"if I want to save some constant"
Where? In the base workspace or in one of the GUI workspaces or somewhere else?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 3월 9일

편집:

2022년 3월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by