Matlab GUI not recognizing variables
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello;
I build a Matlab GUI Code, but I have a problem when I do run it did not recognize variables values to find the row and column of that value.
as seen below;
댓글 수: 2
Jan
2022년 3월 15일
편집: Jan
2022년 3월 15일
What does "it did not recognize variables values" mean exactly?
Please post code as text, such that the readers can suggest modifications using copy&paste. Screenshots makes it much harder to wrie an answer.
What is the purpose of the code? Why do you create variables in the base workspace? What is not working as expected?
After:
assignin('base', 'G91449166', 1);
the variable with this name is created in the command window. If you type there:
disp(G91449166)
1 is replied. But this is rarely useful for the GUI.
답변 (1개)
Walter Roberson
2022년 3월 15일
Make sure you are consistent about how you use x and y . MATLAB prefers y as the row number, because rows are vertical and y is traditionally vertical. MATLAB prefers x as the column number, because columns increase horizontally and x is traditionally horizontal.
If you are expecting that the string G91468166 in handles.input1.string will be interpreted as numeric 1 because you did that assignin() base, then you have not taken into account a couple of things:
- str2double() never pays attention to variables that are set. str2double() pays attention only to the immediate text, and whether the whole of it forms a valid numeric literal. The character vector G91468166 does not form a numeric literal such as 3.8135e-5 so str2double() would say it fails, and convert it to NaN
- the functions that do pay attention to variable names, such as eval(), do not specifically look in the base workspace: they look in the workspace of the current function. The exception is if you use evalin('base')
I suggest you use a different approach. I suggest you use a drop-down list, with the elements arranged in-order. Then instead of looking at the String propertly of a pushbutton, you look at the Value property of the drop-down list, and that will give you the index immediately (just make sure you check whether the Value is [] for the case where nothing has been selected yet.)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!