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!