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!