How do I ensure that the fields within handles stay available throughout GUI Callbacks?
3 views (last 30 days)
Show older comments
Hello
I am currently making a GUI (started with the GUIDE template) that must get and set different values of elements within the GUI in different callbacks.
I am constantly having trouble accessing elements in the handles structure within callbacks with the error message:
Reference to non-existent field 'geo_utitable1'.
Error in axial_fan_performance_4>plot_button_Callback (line 1231) set(handles.geo_utitable1, 'Data', opt_geoData)
This is becoming a huge problem especially when trying to plot in various axes in the GUI.
The error message from above is within a push button call back. The call back first determines which checkbox is selected in another area of the gui. Ultimately, I am trying to get the data values that were computed using the optimization function (fmincon) and populate the uitable with tag 'geo_uitable1'. I also want to plot those values into the axes with tag 'new_axes'. The code works fine until I get in the second if statement...(getting the value of the mlp_button). After that, none of the handles seem to work
if(get(handles.optimization_radiobutton, 'Value')==get(handles.optimization_radiobutton, 'Max'))
set(handles.results_panel, 'Title', 'Optimization Results')
%change title of figure! :)
axes(handles.new_axes)
%get user input
phi_user= str2double(get(handles.input_flowRate, 'String'));
psi_user= str2double(get(handles.input_pressure, 'String'));
%first find the optimal value of the optimizing function...
%display optimal value on the figure
minGeo=handles.R_data(:,1);
minX=[minGeo;phi_user];
maxGeo=handles.R_data(:,2);
maxX=[maxGeo;phi_user];
x0=(maxX-minX)./2;
%get all of the handles structures since i can't get them after inside if statement
targ1=handles.targ1;
targ2=handles.targ2;
maxmin=handles.maxmin;
n=handles.n_points;
set(handles.results_panel, 'Title', 'Optimization')
if(handles.opt_tech==1)
%fmincon was the optimization technique seleced and only one
%parameter can be optimized
x=x0;
options=optimset('Algorithm', 'interior-point', 'Display', 'off');
if(get(handles.mlp_button, 'Value')==get(handles.mlp_button, 'Max'))
%use mlp neural networks for optimization calcualtions
load('mlp.mat')
if (targ1==1)
%psits is the target function
if(maxmin==1)
%maximize this function
[xfinal, fval, exitflag, output]=fmincon(@(x)(-calc_opt(x,mlp.psits)),x0, [],[],[],[],minX, maxX, [], options);
else
%minimize this function
[xfinal, fval, exitflag, output]=fmincon(@(x)(calc_opt(x,mlp.psits)),x0, [],[],[],[],minX, maxX, [], options);
end
end
%update the geo_parameters table...
opt_geoData=xfinal(1:26,1);
%its saying that this handle does not exist!!!! errrgggg
%WHY!!!!!!!!!!
%set(handles.geo_utitable1, 'Data', opt_geoData)
%set(handles.geo_uitable1, 'columnname', 'Optimal Design')
%WONT RECOGNIZE ANY HANDLES IN HERE NOW..... I DONT KNOW
%WHY :(
%axes(handles.new_axes);
plot(phi_user, psi_user, 'r*')
axis(gca,[0,0.7,0,1])
xlabel(gca,'Dimensionless Flow Rate')
ylabel(gca,'Dimensionless Pressure')
title(gca,'Fan Curve')
legend(gca,'Operating Point')
legend(gca, '-DynamicLegend')
%Also must plot the performance curve for the specified geometry
%will always plot 4 graphs...
hold on
%n=handles.n_points;
%the range (x-axis) is dimensionless flow rate
max1=0.7;
min1=0;
h=(max1-min1)/(n-1);
range=[min1:h:max1];
geo_para=repmat(xfinal(1:26,1), [1 n]);
%have input data vary for full range of flow rates, to show
%performance curves
input_data=[geo_para;range];
load('mlp.mat')
y1=mlp.psits(input_data);
y1=y_check(y1, n);
plot(gca, range, y1, 'b--', 'DisplayName', 'Total to Static Pressure')
y2=mlp.psitt(input_data);
y2=y_check(y2,n);
plot(gca, range, y2, 'r--', 'DisplayName', 'Total to Total Pressure')
y3=mlp.etats(input_data);
y3=y_check(y3,n);
plot(gca, range, y3, 'g-.', 'DisplayName', 'Total to Static Efficiency')
y4=mlp.etatt(input_data);
y4=y_check(y4,n);
plot(gca, range, y4, 'k-.', 'DisplayName', 'Total to Total Efficiency')
title('Fan Curve: MLP Network Results')
legend('Location', 'best')
set(axesHandle, 'Tag', 'new_axes')
h=gca;
return
end
if anyone has suggestions about why the handles structure stops letting me access other gui data, please let me know... I've been trying for 2 weeks to figure it out
0 Comments
Answers (2)
nl2605
on 22 Jul 2013
If you are having a problem of updating the handles, you should use guidata(handle to be updated, handles). Here it might be guidata(hObject,handles). Also, to share data withing GUI's, you need to use getappdata and setappdata.
Using setappdata: setappdata(0,handles.geo_utitable1,'geo')
And using getappdata: geo=getappdata(0,'geo')
If you don't understand it you can use this link: http://www.mathworks.de/de/help/matlab/creating_guis/ways-to-manage-data-in-a-guide-gui.html
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!