Reputation: 820
I am trying to work with text function in matlab, and using it as an image as following:
text('HorizontalAlignment' , 'center' ,...
'position' , [.5 .5] ,...
'string' , 'HELLO' ,...
'FontName' , 'Arial' ,...
'FontSize' , 300 ,...
'BackgroundColor' , 'w');
axis off;
g=getframe(gca);
image=g.cdata;
close;
Opening and closing the figure at each time is really bothering me. I googled and I found Save Matlab figure without plotting it? but it did not solve the problem. I tried also set(gca,'Visible','off');
but it does not work either.
Upvotes: 1
Views: 188
Reputation: 10440
Why do you use getframe
and not just print
?
This code seems to do exactly what you want:
fig = figure('Visible', 'off'); % as you know - make the fig invisible
t = text('HorizontalAlignment' , 'center' ,...
'position' , [.5 .5] ,...
'string' , 'HELLO' ,...
'FontName' , 'Arial' ,...
'FontSize' , 300 ,...
'BackgroundColor' , 'w');
axis off;
print(fig,'hello.png','-dpng') % you can chage the settings here to what you need
close(fig)
Upvotes: 0
Reputation: 35525
You should try this Matlab file exchange function. It saves a figure in whatever format you want and you don't need to show it. Anyway, If your program shows figures periodically and you want to show and close them while running try this different commands also:
[commandwindow][2] % Directs the user to command window
close all %closes all figures opened
pause %pauses the run until user presses any key in command window
[movegui][3] %can make a figure be shown where the user sets it (not always in the centre of the screen!)
With the four of them you can make an interesting running by opening and closing figures automatically while the programs goes on and the user has already understand or checked the figures. Combining this with the image save function you can build a pretty nice program!
I am sure that there are much more command useful for this but didn't use them by myself yet
Upvotes: 1