Having a problem building a graph in a GUI. No errors in com. window

1 visualización (últimos 30 días)
Hi Guys!
Here's the deal: I'm trying to build a gui that processes excel data and builds a graph from it. I need to be able to choose between different time intervals for the graph, so I added a popup menu and am trying to put a plot function inside a separate function, so that I could be able to update its callback. As a result, when the user chooses the time step, the graph updates automatically. The problem is, that my command window does not give any errors, but the graph won't show up. Here's the code for graph function:
function updateAxes(hObject, eventdata, handles)
plot(handles.axes1, handles.totalTime,
handles.totalTemperature, 'LineWidth', 2) % Plot the temperature variations on the graph.
grid on; % Turn on the graph grid.
set(gca,'YTick',[50 100:100:2500]); % Y axle ticks.
set(gca,'XTick', 10:10:210); % X axle ticks.
xlabel Time; % x axle label.
ylabel Temperature; % y axle label,
figLeg = legend(handles.axes1, 'test legend'); % create a legend.
handles.figLeg = figLeg;
guidata(hObject, handles);
The values of totalTime and totalTemperature are saved in handles structure in the previous function using guidata(hObject,handles).
Any suggestions?
EDIT 1: It draws the graph when I choose the timestep after clicking the plot button, but don't think it updates the graph after I choose a different timestep. I checked it by putting just a random combination of letters in there and when I choose it, nothing happens. I'd assume it to give an error though. I can Upload the .m file if it helps. I use this function to update the axes. timeStepLisdt is the popupmenu tag.
set(handles.timeStepList, 'Callback', 'projectAlphaT(''updateAxes'',gcbo, [], guidata(gcbo))')
EDIT 2: Right, the problem was in my function for getting values from the popup menu for that time step. Now that I figured it out some weird stuff happens. When I sue my timestep as a constant, everything works. But when I use the following function:
list=get(handles.timeStepList,'String');
val=get(handles.timeStepList,'Value');
timeStep=list{val};
All of my variables saved n handles. structure become unknowns for some reason. So the error I get is:
Error while evaluating uicontrol Callback
Reference to non-existent field 'dtH'.
Error in projectAlphaT>plotPush_Callback (line 166)
dtH = handles.dtH; % Get the handles. values from previous callbacks.
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in projectAlphaT (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)projectAlphaT('plotPush_Callback',hObject,eventdata,guidata(hObject))

Respuesta aceptada

Kokalz
Kokalz el 7 de Ag. de 2012
Figured it out, forgot to add str2doubl after getting the value from the listbox. Sorry!

Más respuestas (1)

Arthur
Arthur el 6 de Ag. de 2012
You have double quotes in the callcabk around updateAxes, that might be the problem. try
set(handles.timeStepList, 'Callback', 'projectAlphaT('updateAxes',gcbo, [], guidata(gcbo))')
  2 comentarios
Kokalz
Kokalz el 6 de Ag. de 2012
Editada: Kokalz el 6 de Ag. de 2012
I believe it's the right way. I used single quotes and it did not work.
I think that the problem might be my way of getting values from the popup menu. I put 3 values in 'String' using property inspector: 0.1, 0.01, 0.001. I use the following function to get the values:
timeStep = get(handles.timeStepList, 'Value').
If I leave it without semicolon to see the values in the Command window, it just keeps giving me:
timeStep =
1
Walter Roberson
Walter Roberson el 7 de Ag. de 2012
Remember, the Value property of a listbox is the index of which entry you have chosen, and is not the numeric value of the corresponding string.
validx = get(handles.timeStepList, 'Value');
valstr = get(handles.timeSteplist, 'String');
curval = str2double( valstr{validx} );

Iniciar sesión para comentar.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by