Borrar filtros
Borrar filtros

How do I ensure that the fields within handles stay available throughout GUI Callbacks?

3 visualizaciones (últimos 30 días)
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

Respuestas (2)

Iain
Iain el 18 de Jul. de 2013
Well, not to be too obvious, but "handles.geo_utitable1" looks like a typo...
  2 comentarios
Erin
Erin el 22 de Jul. de 2013
Well I guess that was a bad example of code then. I have fixed that spelling mistake and triple checked the spelling mistakes of all my handles and I am still getting an error that the fields do not exist. Does the handles structure update or clear or something after you enter certain statements?
Erin
Erin el 22 de Jul. de 2013
Using 'ishandle' at various points in my code, it seems that the handles structure 'forgets' the handle after two things: 1. assigning a local variable, the value of some data in handles ex:
targ1=handles.targ1;
targ2=handles.targ2;
2. after loading an external data structure file
load('mlp.mat')
is there a special line of code that im missing after I perform these tasks?

Iniciar sesión para comentar.


nl2605
nl2605 el 22 de Jul. de 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')
  1 comentario
Erin
Erin el 22 de Jul. de 2013
Thank you
I do use guidata(hObject, handles) after each time i edit a structure in handles. its during a separate callback (when a push button is computed and I want to use external data to compute data and then plot it) that the handles structure no longer recognizes the objects.
I tried loading the data like this:
load('mlp.mat')
guidata(hObject, handles)
but there was an error -----ERROR:H must be the handle to a figure or figure descendent.
do I still need to use getappdata and setappdata is everything is in one GUI, its just in different objects within the GUI.

Iniciar sesión para comentar.

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by