Calling Additional Functions in GUI
Show older comments
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!
Accepted Answer
More Answers (1)
Image Analyst
on 17 Jul 2014
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.
1 Comment
Salaheddin Hosseinzadeh
on 17 Jul 2014
Categories
Find more on Interactive Control and Callbacks 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!