Drawnow in parrallel to main programm

I need to process the data in real time. Now the speed of data processing (data acquisition, primary processing, interframe processing, and so on) is equal to 80 frames per second. I also have to display the data. I made a figure, put all the parameters in manual mode, set the OpenGL rendering mode, reduced the number of displayed points. Updating the graphs I do through set () and drawnow at the end of the loop. Because of the display, the speed drops to 30 frames per second. Below I made an example code.
How to make the figure update parallel to the processing process? I need FPS about 50 - 60.
The dimensions of the data that I build never change. It is always 10 arrays with a fixed size. I thought of running a copy of MathLab and linking them through bin files... But didn't make it.
I read about the fact that the new engine (HG2) is slow (unfortunately, I can not use 2014a). I read all the recommendations for speeding up the graphics update, but I did not find the answer with the parallel update >___<. It suits me if the figure is updated 20 times a second and does not interfere with the processing at all.
Please, help.
% Make figure
figure('Position',[100 100 1600 720]);
% set OpenGL
opengl hardwarebasic;
set(gcf, 'Renderer' , 'OpenGL');
set(gcf, 'RendererMode', 'manual');
% Disable Menu Bar
set(gcf, 'MenuBar', 'none' );
set(gcf, 'ToolBar', 'none' );
set(gcf, 'Color' , [1 1 1]);
% Catch video
subplot(2, 3, 1); plot_Image = image(Video_frame);
ylim([1 480]);
xlim([1 640]);
axis equal tight off;
% Catch Data
subplot(2, 3, 4); hold on;
grid on;
plot_Data_1 = plot(~~~~, ~~~~, 'LineWidth', 1.5);
plot_Data_2 = plot(~~~~, ~~~~, 'LineWidth', 1.5);
plot_Data_3 = plot(~~~~, ~~~~, '-k', 'LineWidth', 0.5);
ylim([-130 -20]);
xlim([ 0 Data_max]);
legend('~~~~', '~~~~', '~~~~');
xlabel('~~~~', 'FontName','Times New Roman','Fontsize',14);
ylabel('~~~~', 'FontName','Times New Roman','Fontsize',14);
set (gca , 'FontName','Times New Roman','Fontsize',14);
% and so on
for i = 1 : Max_Frames
% Data collection and processing
data_acquisition = get_data()
video_acquisition = get_frame()
data_processing = processing()
% Updated figure
set(plot_Data_1, 'YData', data_processing(1, :))
set(plot_Data_2, 'YData', data_processing(2, :))
set(plot_Data_3, 'YData', data_processing(3, :))
set(plot_Image , 'CData', video_acquisition )
drawnow % too slow, wanna make it in parallel
end

1 Comment

If you could provide an example with typical data, I could provide more details on where the time is spent.
At a quick glance, I suspect your overall strategy is good and the time to draw is getting in your way.
For situations like this where the loop time is faster than the draw time, drawnow supports an option to limit the number of draws attempted. If you add the option "limitrate" to your drawnow command, drawnow will only attempt updates every 50ms for a target rate of 20 frames per second.
Please let me know if this helps in your situation.

Sign in to comment.

 Accepted Answer

It is not possible to move the graphics into a worker. You can move other activity into a worker and communicate back, but you cannot move graphics.
R2017a has new facilities for workers to communicate back to the main process; look at the pollable data queue for example.

1 Comment

Thank you very much for your reply. This is very similar to a good solution. It is a pity that they realized it only in 2017 ...
And thank you very much for your answers to other questions. I read this forum for a long time and your answers often helped me.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Asked:

on 10 Jun 2017

Commented:

on 11 Jun 2017

Community Treasure Hunt

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

Start Hunting!