hello.. Is there a code to load a value to the popup menu from .mat file… there should be an option to select or change the data even after loading the value!!
Best Answer
hello Yoav Livneh and Geoff Hayes.. thanks for your valuable comments.. I somehow got the answer for the above question and I wud like to share with you ppl..
I have 5 options in the POPUP menu as awake sleeping waiting in gym out
we have to compare the data got from the .mat file and then change the value property according to it. he I'm sharing my code of load push button..
call back function of pushbutton will look like below
function load_pb_Callback(hObject, eventdata, handles) [filename pathname] = uigetfile('*.mat','Select the MATLAB code file'); L = load( fullfile( pathname, filename ) ); varnames = fieldnames(L); % Message=num2str(L.(varnames{1})); Status= num2str(L.(varnames{2})); if strcmp(Status,'awake') set(handles.popup,'value', 1) elseif strcmp(Status,'sleeping') set(handles.popup,'value', 2) elseif strcmp(Status,'waiting') set(handles.popup,'value',3) elseif strcmp(Status,'out') set(handles.popup,'value', 5) elseif strcmp(Status,'in gym') set(handles.popup,'value', 4) end
Max - there are probably several different ways to do this, so here is one. Let's assume that you have two GUIs namedGui1 andGui2 and that they are distinct GUIs (i.e. you are not running two instances of the same one). In the Property Inspector forGui1, set theHandleVisibility property toon, and theTag property toGui1. This will allow us to search for the GUI given its (unique) tag. Do the same forGui2 (except name the tagGui2). Save both.
Now suppose that inGui2 you want access to some of the data inGui1. What you require, is the handle to the latter. In a (say) push button callback ofGui2, you can add the following code
function pushbutton1_Callback(hObject, eventdata, handles)
% get the handle of Gui1
h = findobj('Tag','Gui1');
% if exists (not empty)
if ~isempty(h)
% get handles and other user-defined data associated to Gui1
g1data = guidata(h);
% maybe you want to set the text in Gui2 with that from Gui1
% maybe you want to get some data that was saved to the Gui1 app
x = getappdata(h,'x');
end
The above example tests out two ways in which we can get data from the other GUI - use eitherguidata which gives us the handles to all widgets ofGui1 AND any user-defined data that had been saved inGui1 to thehandles object as
function pushbutton3_Callback(hObject, eventdata, handles)
% in some Gui1 callback, we create the following xData field in the handles
% structure
handles.xData = -2*pi:0.0001:2*pi;
% now we save the data
guidata(hObject,handles);
We then access this data as shown previously.
The other way is to use thesetappdata andgetappdata pairings. Using the previous callback forGui1, we can save the app data as
function pushbutton3_Callback(hObject, eventdata, handles)
% in some Gui1 callback, we create the following xData field in the handles
% structure
handles.xData = -2*pi:0.0001:2*pi;
% now we save the data
guidata(hObject,handles);
setappdata(handles.Gui1,'x',[1:53]);
and then retrieve it withgetappdata.
NOTE how we use must use thehandles.Gui1 to save/set the data. And that is it. Try the above and see what happens!
'handles' is just a structure. It goes out of scope like any other variable when your function ends so you have to give this instruction to tell the GUI to replace its version of the handles struct with your updated one.
Best Answer