sorry for the new thread...new to this forum
Figure Visibility and Save
533 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
John F
am 11 Jul. 2012
Beantwortet: Igor Varfolomeev
am 13 Nov. 2015
Hi everyone,
I'm plotting to an "invisible" figure and I'm almost positive it's working correctly.
I save the figure both as a 'fig' and as a 'jpg'.
When I go to open the 'jpg' format, the figure opens just as I would expect it to and I can see the plots.
However, when I try to access the 'fig' format, nothing opens up. I believe this is because the "visible" setting is still set to "off".
This is obviously a problem.
Is there any way to set the visibility setting to "on" during saving? (WITHOUT ever having the figure open up?)
I'd still like to keep the image's visibility to "off" while running my code.
Thanks!
JF
Akzeptierte Antwort
Thomas
am 11 Jul. 2012
a=1:4;
f = figure('visible','off');
plot(a)
saveas(f,'newout','fig')
Now to reopen the figure
% to open the figure
openfig('newout.fig','new','visible')
3 Kommentare
Alessandro La Chioma
am 27 Okt. 2015
I wrote a little function to open these invisible figures with a dialog box:
function open_InvisibleFig
init_dir = pwd;
FigToOpen = cellstr(uigetfile('*.fig','Select the Figures to open...', init_dir, 'MultiSelect','on') );
for ind = 1 : length(FigToOpen)
openfig(FigToOpen{ind},'new','visible')
end
Weitere Antworten (3)
Eric Salemi
am 25 Jun. 2014
I recently solved this issue by directly modifying the saved figure:
% h is the variable containing
% the invisible figure handle
hgsave(h,filename);
map = load(filename,'-mat');
names = fieldnames(map);
for j = 1 : numel(names)
map.(names{j}).properties.Visible = 'on';
end
save(filename,'-struct','map');
Now, whenever you open the figure (command-line, explorer, etc.) it will be visible.
3 Kommentare
Igor Varfolomeev
am 12 Nov. 2015
I've also tried a bit different approach, matfile() - based.
In this case figure does get visible. But.. it's also visible in the "modification" process:
function test_hgsave_invis2vis_v2_figv7( )
% Tests matfile()-based approach to figure editing, '-v7.3' case.
% The aim is to change figure 'Visible' property to 'on', without actually
% showing it. However, it fails - the figure is shown.
% Tested in R2015b.
%%create test figure
hf = figure('visible','off');
ha = axes('Parent',hf);
hp = plot(ha,1:10,(1:10).^2); %#ok<NASGU>
% naive hgsave use, resulting in invisible figure
hgsave(hf,'test_invisible.fig','-v7.3');
%%modify mat file without loading all vars to RAM
m = matfile('test_invisible.fig','Writable',true);
x=m.hgS_070000(1,1); % '070000' corresponds to '-v7.3'
x.properties.Visible='on';
m.hgS_070000(1,1) = x;
x=m.hgM_070000(1,1);
y=x.GraphicsObjects(1,1);
z=y.Format3Data(1,1);
z.Visible='on'; % trick is - here figure becomes visible.
% Note:
% This command:
% >> m.hgM_080000(1,1).GraphicsObjects(1,1).Format3Data(1,1).Visible='on';
% generates the following error:
% Cannot index into 'hgM_080000' because MatFile objects only
% support '()' indexing.
delete(m); % fclose();
end
Just the same for v8 figure file format:
function test_hgsave_invis2vis_v2_figv8( )
% Tests matfile()-based approach to figure editing, 'compact' case.
% The aim is to change figure 'Visible' property to 'on', without actually
% showing it. However, it fails - the figure is shown.
% Tested in R2015b.
%%create test figure
hf = figure('visible','off');
ha = axes('Parent',hf);
hp = plot(ha,1:10,(1:10).^2); %#ok<NASGU>
% naive hgsave use, resulting in invisible figure
savefig(hf,'test_invisible.fig','compact');
%%modify mat file without loading all vars to RAM
m = matfile('test_invisible.fig','Writable',true);
assert(isempty(m.hgS_080000)); % this prop is empty in 'compact' case
x=m.hgM_080000(1,1); % '080000' corresponds to 'compact'
% Warning: The file 'w:\Tfit\Matlab\SavedFigures\SaveFigure_savefig(compact)
% (naive).fig' was saved in a format that does not support partial loading.
% Temporarily loading variable 'hgM_080000' into memory. To use partial loading
% efficiently, save MAT-files with the -v7.3 flag.
% > In matlab.io.MatFile/inefficientPartialLoad (line 144)
% In matlab.io.MatFile/subsref (line 462)
%
y=x.GraphicsObjects(1,1);
z=y.Format3Data(1,1);
z.Visible='on'; % trick is - here figure becomes visible.
% Note:
% This command:
% >> m.hgM_080000(1,1).GraphicsObjects(1,1).Format3Data(1,1).Visible='on';
% generates the following error:
% Cannot index into 'hgM_080000' because MatFile objects only
% support '()' indexing.
delete(m); % fclose();
end
Baha
am 14 Okt. 2015
Bearbeitet: Baha
am 14 Okt. 2015
This code below still doesn't work for me. When I click on the figure, it still doesn't open up.
Anyone was able to turn the visibility of the figure on without displaying it?
filename = ['PeaksFile0',num2str(111),'.fig'];
h = figure('visible', 'off');
surf(peaks);
savefig(filename)
hgsave(h,filename);
map = load(filename,'-mat');
names = fieldnames(map);
for j = 1 : numel(names)
map.(names{j}).properties.Visible = 'on';
end
save(filename,'-struct','map');
1 Kommentar
Igor Varfolomeev
am 13 Nov. 2015
Yep, it looks like this method got obsolete, and is not working in R2015a and R2015b.
Igor Varfolomeev
am 13 Nov. 2015
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!