Saveas (visible, off)

46 ビュー (過去 30 日間)
Aadil
Aadil 2012 年 4 月 3 日
回答済み: Igor Varfolomeev 2015 年 11 月 13 日
Hi I'm working on a script that creates a load of plots then saves them as individual fig files as well as all into a pdf file.
The problem I'm having is that although I've set visible to off, the plots still come up after going through the saveas function, so now I have to resort to using 'close all' after each graph. But even close all cause the graphs to flash up momentarily.
This is very annoying as I want the whole process invisible and not interfering with my desktop space.
Please help
Thanks
This is my script:
%%Throttle
i = i + 1;
figure(i)
set(gcf,'Visible','off','PaperOrientation',
'landscape','PaperPositionMode','manual','PaperPosition',[0.1, 0.1,30, 20]')
set(gca,'fontsize',10);
% Set Parameters to Plot
if exist('Accelerator_Pedal_Position'); plot(Elapsed_Time, Accelerator_Pedal_Position,'LineWidth', 1 ); else plot (0,NaN,'w'); end;
h=legend('Accelerator\_Pedal\_Position');
set(h,'fontsize',6);
% Set title for plot
title(['220HP'; 'Automated Manual';raw(3);'Throttle']);
%Set Labels for X and Y Axes'
xlabel ('Elapsed Time (s)');
ylabel ('Accelerator\_Pedal\_Positionn (%)')
xlim ([-inf inf])
grid on;
box on;
fpath = 'D:\Users\km933\Documents\MATLAB\Field Test v1';
saveas(figure(i), fullfile(fpath, 'Throttle'), 'fig');
print -dpsc -append myfile
close all
  1 件のコメント
Aadil
Aadil 2012 年 4 月 4 日
anyone?

サインインしてコメントする。

採用された回答

Robert Cumming
Robert Cumming 2012 年 4 月 4 日
When you create your figure set the position to be off your screen, i.e.
'position', [10000 10000 800 600]
That way it wont be displayed on your desktop.
  4 件のコメント
Aadil
Aadil 2012 年 4 月 4 日
Great, this works nice one mate cheers
Aadil
Aadil 2012 年 4 月 11 日
right, after checking my figure files I've discovered that this method causes the figures to be invisible ie. when you click to open the file nothing opens as its positioned off the screen

サインインしてコメントする。

その他の回答 (4 件)

Titus Edelhofer
Titus Edelhofer 2012 年 4 月 4 日
Hi Aadil,
the problem I guess is the call figure(i) in saveas. Just use
save(i, fullfile(...));
One minor issue: do you need the figure to be numbered? Otherwise I would usually suggest something like
% create invisible figure
hFigure = figure('Visible','off','PaperOrientation',
'landscape','PaperPositionMode','manual','PaperPosition',[0.1, 0.1,30, 20]');
% do your plotting etc.
% and save:
save(hFigure, fullfile(...));
% and close it:
close(hFigure);
Titus
  4 件のコメント
Jan
Jan 2012 年 4 月 4 日
@Aadil: Can you confirm, that the SAVE command makes the figure visible?
Either use the debugger by setting a breakpoint in the code and step through the program line by line, or use "disp('before save'); pause(1);" and "disp('after save')".
Aadil
Aadil 2012 年 4 月 4 日
I'm not sure,I had a look at the code and don't really understand it

サインインしてコメントする。


Jan
Jan 2012 年 4 月 4 日
Some functions to copy the contents of a figure requires an enabled visibility. I assume it is print in your case, but I've seen this behaviour for getframe only yet.
I assume there is no workaround and getting annoyed is not good solution. I suggest a coffee break.
  2 件のコメント
Aadil
Aadil 2012 年 4 月 4 日
no I've tried it with just the print function and the graphs stay invisible, its when I want them to be saved as fig files that causes them to flash up again
I'm assuming this flashing up of graphs is also slowing the process down?
Robert Cumming
Robert Cumming 2012 年 4 月 4 日
yes the rendering will be making it slower.

サインインしてコメントする。


Sebastian
Sebastian 2013 年 1 月 3 日
I've also created a routine like Aadil in which many plots were created, saved, reloaded, updated and again saved... all automagically.
I created it in Matlab 2010a (Win XP) and it worked great, as the figures were all the time invisible (no need to plot outside the screen), and it worked fast...
Now that I have R2011b and Win 7, the routine became slower and it shows every figure before it is saved.
Any way to change it back ? is it Win 7 or the newer Matlab Version ?
Best regards,

Igor Varfolomeev
Igor Varfolomeev 2015 年 11 月 13 日
If anyone is still looking for an answer, take a look at this post - I've just tried to collect all known workarounds in a single post.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by