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!