Calling Additional Functions in GUI
1 次查看(过去 30 天)
显示 更早的评论
Hello Everyone!
Thanks for your attention.
I've created a GUI using GUIDE with lots of edit boxes, what I do in the edit call backs is to check if the input value is valid or not.
I've 3 push buttons, I want to acquire the edit boxes value in the push buttons call back, so I thought of creating a function to do that, also there is a series of plots. So I defined 2 functions at the end of the GUI m file, "Plotter" and "ValueCollector", to plot on the axes which is on the form, and second is to read all the edit boxes values at once.
PROBLEM is: "ValueCollector" does not work in push buttons call back, but it works in the dropdown menu call back, buttons are off until user pick a choice from the dropdown menu, then they will be on, to dropdown menu runs the "ValueCollector" for the first time (I don't know if it's related or not)
% Probe Selector is the popup menu
function Probe_Selector_Callback(hObject, eventdata, handles)
handles = valueCollector(handles);
handles.CurrentProbe.X = handles.probe.info(handles.CurrentProbe.Num,2);
handles.CurrentProbe.Y = handles.probe.info(handles.CurrentProbe.Num,3);
% some processing based on values collecter by ValueCollector which is
% correct
plotter(handles); % Plots everything
set(handles.arb_button,'Enable','on');
guidata(hObject,handles);
function arb_button_Callback(hObject, eventdata, handles)
handles = valueCollector(handles); % this is not working!!
plotter(handles);
% some processing
guidata(hObject,handles);
function [handles] = valueCollector (handles)
% this collects all the property values of the edits
handles.initial.Fs = str2num(get(handles.ArbFs_edit,'String'));
handles.initial.cycles = str2num(get(handles.cycles_edit,'String'));
handles.initial.fc = str2num(get(handles.fc_edit,'String'));
handles.initial.radSize = str2num(get(handles.pattern_edit,'String'))/2;
handles.initial.phaseShift=str2num(get(handles.phaseShift_edit,'String'))*pi/180;
handles.initial.Mu = str2num(get(handles.Mu_edit,'String'));
handles.initial.G = str2num(get(handles.G_edit,'String'));
handles.CurrentProbe.Num = get(handles.Probe_Selector,'Value');
demo = get(handles.checkbox1,'Value');
if demo == 1
handles.initial.demo = 'demo';
else
handles.initial.demo = 'non';
end
"ValueCollector" works file in the popup_callback but it does not work in 2 push buttons that I have! the variable handles that returned by ValueCollector function is not updated!
I used guidata(hObject,handles) at the end of the ValueCollector but the problem is still remains!
I tried ValueCollector(hObject,eventdata,handles) nothing chande, I add a guidata(ho...) after calling ValueCollector in the push buttons, still not working! I'm running out of ideas.
Thanks for your help in advance!
0 个评论
采纳的回答
Joseph Cheng
2014-7-17
Not sure what is going on since i can't reproduce it not updating. Here is a quick test i did using a few edit boxes and pushbuttons. the first one gets and stores whats inside the edit boxes. the second buttons displays whats in handles into the static text fields.
2 个评论
Joseph Cheng
2014-7-17
I don't think the guidata() at the end of the popup would do anything strangely. Maybe put some breakpoints in the code to and see where the handles update breaks down.
更多回答(1 个)
Image Analyst
2014-7-17
Get the string value of edit boxes, not the value, even if what's in there is a number:
handles.X = str2double(get(handles.edit1,'String'));
handles.Y = str2double(get(handles.edit2,'String'));
but that's still not very robust since you are not checking if the user put in some non-numerical text instead of a number.
另请参阅
类别
在 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!