Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
GUI and dealing with functions
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am new to the GUI and I have a problem is that very basic. The question is regarding dropdown menu. When I select a value in dropdown menu lets say 3 and assign it to some variable lets say K. I want it to be used in other functions but other functions don't see it. I tried global variable but that doesn't work.
Can you help me. Thank you
0 Kommentare
Antworten (2)
Image Analyst
am 25 Jun. 2012
If you're using GUIDE, you'd do
global K;
K = get(handles.popmenu1, 'Value');
and then put global K; into every other function that needs to see K. Did you do that?
Or else you can just use that "get" line in every other function that needs K and forget about setting it to a global variable, as long as that function can see the handles structure, which all call backs can. If you need it in a function you wrote, a non-callback function, then you'd have to pass handles in via the argument list.
Alternatively, did any of the ideas in the FAQ work for you? http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
2 Kommentare
Image Analyst
am 25 Jun. 2012
No. If it's global, you don't need to pass it via arg lists anymore. Just declare it global again inside any function that needs to "see" it.
function myfunction()
global K;
try
% Your code goes here
catch ME
errorMessage = sprintf('Error in myfunction().\nThe error reported by MATLAB is:\n\n%s', ME.message);
uiwait(msgbox(errorMessage));
end
John
am 25 Jun. 2012
you can either, as Image Analyst states, get(handles.dropdownmenu1,'Value') during each function or you can simply store it in the structure handles.
For example if the name of the dropdown menu is dropdownmenu1. then:
handles.value = get(handles.dropdownmenu1,'Value');
%Also add the following line at the end of the function
guidata(hObject,handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Now 'handles.value' should be accessible to every other function.
0 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!