How can I have access to a string variable selected by a popup munu in GUI in Workspace via evalin?
Show older comments
Hello,
I am trying to see the string that is selected in a popup menu of a gui file in workspace. There is a popup menu in the gui that selects among different COM ports. In popup callback function, I want to see the selected COM string in the workspace. But when I use evalin, it makes error. this is the code that I have written in the popup callback function:
str = get(source, 'String');
val = get(source,'Value');
evalin('base','COM = str{val}');
and I want to see COM in workspace.
Thanks in advance,
Answers (1)
Image Analyst
on 28 Apr 2013
Edited: Image Analyst
on 28 Apr 2013
0 votes
It's usually not recommended to toss your function's variables into the base workspace with assignin() (which I assume you meant instead of evalin). Why do you want to do that? See the FAQ: http://matlab.wikia.com/wiki/FAQ?&cb=628#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F I have long 5000-line long scripts using GUIDE and doing all kinds of complicated things and I've never, ever had to copy any of my variables into the base workspace.
3 Comments
Image Analyst
on 29 Apr 2013
I believe the most recommended way is to use getappdata() and setappdata(), probably followed by attaching a new field to the handles structure, or declaring it global.
Jan
on 29 Apr 2013
@Samar: EVAL, EVALIN and ASSIGNIN are fine method to drive the programmer into troubles. Avoiding them is a good strategy to avoid problems.
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!