How to pass data between GUI and different .m file
1 次查看(过去 30 天)
显示 更早的评论
I have a GUI that allow the user to choose one of filtering type from the popup menu.
The popup menu program is written in different .m file.
In only one of the selection, what should happen are:
-one message box should popup that says the user should key-in the parameter inside the box below.
-the appropriate box that I set to be not visible should be visible when the selection is being choose.
Then, when the user have key-in the parameter that is needed and click the pushbutton to do the filtering, the result should be plotted.
My problem is that I want to do the function inside the popup menu .m file but I can't access the data that is being key-in inside the GUI. I've tried using this codes but it didn't work:
if get(handles.cwt_apply,'Value')
scale=str2num(get(handles.cwt_scale,'String'));
switch get(handles.cwt_menu,'Value')
case 1
for i=1:length(datain(:,1))
dataout = cwt(datain(i,:),scale,'cmor1-1.5');
end
case 2
for i=1:length(datain(:,1))
dataout = cwt(datain(i,:),scale,'morl');
end
case 3
for i=1:length(datain(:,1))
dataout = cwt(datain(i,:),scale,'haar');
end
end
end
The error is Undefined variable "handles" or class "handles.cwt_apply".
Though I've manage to make the box visible, but the codes is written in the main GUI program. Does this affect the passing of data? The message box is also written in the main GUI program. This is the codes:
if get(handles.filter_menu,'Value') == 10;
h = msgbox('For CWT, please choose appropriate parameter inside the box below');
set(handles.cwt_scale,'Visible', 'on');
set(handles.cwt_menu,'Visible','on');
set(handles.text52,'Visible','on');
set(handles.cwt_apply,'Visible','on');
else
set(handles.cwt_scale,'Visible','off');
set(handles.cwt_menu,'Visible','off');
set(handles.text52,'Visible','off');
set(handles.cwt_apply,'Visible','off');
end;
Besides that, the message box has a red line graph that suppose to be plotted on the appropriate axes. I can't seem to make it disappear.
Thanks in advance for the help..
0 个评论
采纳的回答
Walter Roberson
2011-3-11
We need to see the code for the popup.m file, in particular the 'function' header or the place you are initializing handles. And we need to see the code near the place that would invoke popup.m
5 个评论
Walter Roberson
2011-3-12
Did you add
handles = guidata(hObject);
as the first line of the routine, right after the 'function' statement ?
更多回答(3 个)
Jason Kaeding
2011-3-11
Use the guidata() function.
You would tag a callback to each control. Depending on the control, it would either read the guidata or write to the guidata (to update the current state).
Typically I use a struct in my guidata to store the different information.
To me, it sounds like you need to make the handles of the items in the GUI part of the guidata.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!