How to publish text and pictures in a loop

조회 수: 5 (최근 30일)
per isakson
per isakson 2012년 7월 7일
댓글: jfaulhab 2018년 12월 13일
I want to make a simple catalog over screen clips, which I captured with the Windows 7 Snipping Tool. That's simple with a for-loop, I thought. That would output text, picture, text, picture, etc. However, the script below produces a block of text followed by the pictures. (R2012a).
Next, I included the text in the figure with the function, title. However, I have set a max width as an publish option. In many cases that made the text unreadable small.
Using the errordlg to show the text is not attractive.
Have I missed an option in publish?
Is there a simple work around?
%%Snipping Tool clips
file_spec = fullfile( folder_spec, '*.png' );
sad = transpose( dir( file_spec ) );
for sa = sad
fprintf( '%s | %8u | %s\n', datestr(sa.datenum,31), sa.bytes, sa.name )
... create a figure with an axes
pic = imread( fullfile( folder_spec, sa.name ), 'png' );
imagesc( pic )
end

채택된 답변

Sean de Wolski
Sean de Wolski 2013년 7월 29일
is a code secton break. You can find more information on it here:
You may also be interested in snapnow() to force publish to take a snapshot.
doc snapnow
  댓글 수: 1
jfaulhab
jfaulhab 2018년 12월 13일
Is there also a way to publish picture, text, picture, text... inside a loop? Normally with snapnow, the figure is placed at the bottom of the section. Any idea how to accomplish this?
Many thanks in advance!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

per isakson
per isakson 2012년 7월 8일
편집: per isakson 2013년 8월 8일
I've found the answer, which raises a new question. How come I missed the importance the position of "%%" relative to the loop?
A "%%" need to be inside the loop to "flush the output buffer". The code below does it.
%%Snipping Tool clips
file_spec = fullfile( folder_spec, '*.png' );
sad = transpose( dir( file_spec ) );
for sa = sad
fprintf( '%s | %8u | %s\n', datestr(sa.datenum,31), sa.bytes, sa.name )
... create a figure with an axes
pic = imread( fullfile( folder_spec, sa.name ), 'png' );
imagesc( pic )
end
.
Cont.
The code below illustrates the role of cell break, %%, inside the loop. Only Test 1 produces the result
  • text,picture, text,picture, text,picture
rgb = imread('ngc6543a.jpg');
%
%%Test 1
for ii = 1 : 3
fprintf( 'Picture: %u', ii )
image(rgb);
end
%%Test 2
for ii = 1 : 3
fprintf( 'Picture: %u\n', ii )
image(rgb);
end
%%Test 3
for ii = 1 : 3
fprintf( 'Picture: %u\n', ii )
figure, image(rgb);
end
%%Test 4
for ii = 1 : 3
fprintf( 'Picture: %u\n', ii )
figure, image(rgb);
drawnow()
end
.
2013-08-08: With R2013a and snapnow, this example produces the desired result
  • text,picture, text,picture, text,picture
%%Test with snapnow
for ii = 1 : 3
fprintf( 'Picture: %u\n', ii )
figure, image(rgb);
snapnow()
end
Since when has snapnow been around? Sean, thanks for making me aware of it.
  댓글 수: 8
francesco
francesco 2013년 7월 22일
Yes, I think this is the only to overcome the problem. Thank you very much for your help ! Best regards
Peter
Peter 2013년 7월 29일
And something else to watch out for: Following this answer I discovered (2012b) that a try catch block around the section ment to flush the figures is a problem. For me, I had to remove the try catch, otherwise the %% had no effect in within the loop.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Results, Reporting, and Test File Management에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by