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

Viewed 656

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?

1 Answers
Related