Having a problem building a graph in a GUI. No errors in com. window
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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))
0 commentaires
Réponse acceptée
Plus de réponses (1)
Arthur
le 6 Août 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 commentaires
Walter Roberson
le 7 Août 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} );
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!