Having a problem building a graph in a GUI. No errors in com. window
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(1 个)
Arthur
2012-8-6
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 个评论
Walter Roberson
2012-8-7
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} );
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!