Updating a figure in a GUI pops up a new figure, what's wrong?

조회 수: 4 (최근 30일)
FX
FX 2016년 8월 12일
답변: FX 2016년 8월 13일
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.

채택된 답변

FX
FX 2016년 8월 13일
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

추가 답변 (1개)

Adam
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 );
  댓글 수: 1
FX
FX 2016년 8월 13일
편집: FX 2016년 8월 13일
Well this works partially with plot, thank you. But still a new figure is popping up even that the data is going to the right figure. When I close that figure manually it pops up again during the next timer execution.
Also, how about the function highlow which can return a handle but does not take one as an input argument, can I somehow use the handle it returns to draw on the axes on the GUI?
Maybe I should give some feedback to Matlab about the candle function that it should take axes as an input.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by