I got the question answered succesfully at Stackoverflow. Here is the url: http://stackoverflow.com/questions/38890375/updating-chart-in-a-gui-with-timer-creates-a-new-figure-axes
Updating a figure in a GUI pops up a new figure, what's wrong?
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to make a program that displays live chart data from a broker once in a period. The period could be for example 5 seconds or 15 minutes.
I have made a GUI and a Timer but always when the program starts all the updated candles comes to new figure (only one) but not into the figure in the GUI.
Attached is some code:
This is in the openingFcn of the GUI .m-file
handles.timer = timer(...
'ExecutionMode', 'fixedRate', ... % Run timer repeatedly
'Period', 5, ... % Initial period is 5 sec.
'TimerFcn', {@updateChart,hObject}); % Specify callback
guidata(hObject, handles);
start(handles.timer);
% Choose default command line output for OAPIGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
And this is the updateChart callback funtion:
function updateChart(hObject,eventdata,hfigure)
% Get new data, one candle at a time
[ openBid, openAsk, highBid, highAsk, lowBid, lowAsk, ...
closeBid, closeAsk, volume] = ...
DataExtract(GetHistory('EUR_USD', 'S5', '1'));
handles = guidata(hfigure);
% How many times the chart has already updated
k = handles.timer.TasksExecuted
% Populate the beginnings of the vectors with NaNs to draw the newest
% candle on the right spot on the chart.
highBid = [NaN(k,1) ; highBid];
lowBid = [NaN(k,1) ; lowBid];
closeBid = [NaN(k,1) ; closeBid];
openBid = [NaN(k,1) ; openBid];
axes(handles.axes1);
candle(highBid, lowBid, closeBid, openBid);
hold on;
I have read https://se.mathworks.com/matlabcentral/answers/102384-how-do-i-make-my-gui-plot-into-an-axes-within-the-gui-figure-rather-than-inside-of-a-new-figure-in-m but I'm still getting a new figure. The first candle goes to the GUI's figure which is strange.
No matter which plotting command I use, the problem can be reproduced with just the 'plot' command, for instance.
댓글 수: 0
채택된 답변
추가 답변 (1개)
Adam
2016년 8월 12일
'candle' looks like a very old function and does not seem to have a version that allows you to plot on a specified axes, but plot certainly does so e.g.
plot( hAxes, xData, yData )
is what you should always use rather than
axes( hAxes )
plot( xData, yData );
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!