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!