Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control order of printing and figures in MATLAB 'publish' function

Tags:

matlab

I have a simple MATLAB script which prints some text and displays figures in a loop, for example

for i = 1:3

    x = randn(100, 1);

    fprintf('Mean = %.2f\n', mean(x));
    fprintf('Std  = %.2f\n', std(x));

    figure;
    plot(cumsum(x));

end

I want to use the publish function to create a HTML file containing the output of this script, with the text and figures interleaved as they are in the loop, i.e. they order that they appear in the output should be

  1. Text from the first loop run
  2. Figures from the first loop run
  3. Text from the second loop run
  4. Figures from the second loop run
  5. Text from the third loop run
  6. Figures from the third loop run

However, the output currently appears in the following order

  1. Text from the first loop run
  2. Text from the second loop run
  3. Text from the third loop run
  4. Figures from the first loop run
  5. Figures from the second loop run
  6. Figures from the third loop run

How can I achieve the desired output?

like image 969
Chris Taylor Avatar asked Sep 15 '17 07:09

Chris Taylor


1 Answers

Within the loop, just before the end, include the command snapnow. That will force the publishing routine to take the snapshot there and then, rather than waiting for the end of the loop to collect all the images.

like image 191
Sam Roberts Avatar answered Nov 05 '22 00:11

Sam Roberts