-1

I have a working MATLAB program measures data to tune a machine in real-time using the SOAP library from MATLAB (several measurements per second). It was working well, updating two figures, each containing four sub-plots as the tuning proceeds. Recently the plot has stopped updating, just showing a grey box (actually two shades of grey if you re-size the window).

I can tell that the program is running properly from debug information written to the MATLAB console. Also, sometimes the plots update in a burst, adding many new points, when they should be updating with every new point.

I have made several small changes to the code to reduce the comms traffic, but my biggest recent change is to all lots of calls to toc to measure the time taken in various parts of the code, with a single tic at the start.

Is it possible these extra timing calls could be suppressing the plots?

Here is a cut down copy of my code. It is a nested function that makes use of some configuration data from the top level function. The figure is one of two created in the top level function then completely redrawn as new data arrives.

function acc_plot(accFig, accData)
  figure(accFig);
  sp1 = '221';

  % Plot current vs raw position
  subplot(sp1);
  plot(xRawPos,yCfbDcM,'r.', xRawPos,yCfbDcP,'b.')
  hold on;
  if tuneConfig.dualSensors(accData.axisIx)
    plot(xRawPosB,yCfbDcM,'g.', xRawPosB,yCfbDcP,'m.')
  end
  title(['acc check ' tuneConfig.axisNames{accData.axisIx}])
  ylabel('CFBM(r)/CFBP(b) [A]')
  xlabel(xPosLabel)
  grid on
end
Nigel Davies
  • 1,640
  • 1
  • 13
  • 26
  • Did you try adding "drawnow"? – Shanqing Cai Mar 20 '14 at 09:42
  • Apart from that, maybe you should add "clf" after "figure(accFig)", just to make sure the the data associated with previous frames are properly cleaned up, so that memory clogging will not happen. – Shanqing Cai Mar 20 '14 at 09:44
  • I had tried "drawnow expose" which did not work. Just "drawnow" on its on is working better. – Nigel Davies Mar 20 '14 at 10:34
  • drawnow without any options fixes the problem. clf does not make any difference. @scai, if you make your comment an answer, I can give you the credit you deserve. – Nigel Davies Mar 20 '14 at 11:08
  • if your looking for a pointer to avoid redrawing the whole graph, take a look at setting the YDataSource(s) see [Lineseries Properties](http://www.mathworks.co.uk/help/matlab/ref/lineseriesproperties.html) – RTL Mar 20 '14 at 11:30
  • Thanks for the suggestion. I found this http://stackoverflow.com/questions/13102654/how-should-i-update-the-data-of-a-plot-in-matlab, which makes me want to do just that. – Nigel Davies Mar 20 '14 at 13:51

1 Answers1

1

Add "drawnow" to your function to force refresh.

Shanqing Cai
  • 3,756
  • 3
  • 23
  • 36