-
Notifications
You must be signed in to change notification settings - Fork 0
/
figConvert.m
72 lines (62 loc) · 1.89 KB
/
figConvert.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function [newFigNr] = figConvert(figNr, subplotDim1, subplotDim2)
% Convert old styled figure by subplot() function, to tiledlayout.
% Param: figure number or path to *.fig file
% Return: new Figure Number
% Example 1:
% figConvert(1);
% Example 2:
% newConvFigNr = figConvert(gcf().Number)
% Created 20.07.2024 by PSW in the Odyseja
if(nargin < 1) disp("No params. Set figure number or path."); end
if(isnumeric(figNr))
% ok, do nothing
else
if(isstring(figNr))
% o = openfig("Collegium_Medicum_figPW_Spectrum_for_intra-group_raw_&_power_signals_1.fig");
o = openfig(figNr);
figNr = o().Number;
else
error("Unknown param");
end
end
if(nargin < 3)
subplotDim1 = 4;
subplotDim2 = 2;
end
nrOfPlots = subplotDim1*subplotDim2;
h = figure(figNr);
tmp = h.Children;
SGtitle = '';
% try
for i = 1:length(tmp)
tmp = h.Children(i);
if(strcmp(get(tmp, 'type'),'tiledlayout'))
warning(sprintf("The figure(%d) have Tiled Layout, so can't be converted again. Breaking oparation without return value!", figNr));
return
end
if(strcmp(get(tmp, 'type'), 'subplottext') == 1 )
SGtitle = tmp.String;
end
end
newFigHandle = figure;
tcl=tiledlayout(subplotDim1, subplotDim2);
% tcl = tiledlayout('flow')
for( sp = 1:nrOfPlots)%numel(h.Childrens)
figure(figNr); subplot(subplotDim1, subplotDim2, sp);
ax = gca;
figure(newFigHandle);
if(sp == nrOfPlots) for( j = 1:nrOfPlots-1) delete(nexttile(nrOfPlots)); end; end
a = nexttile;
a.Layout.Tile = nrOfPlots;
if(sp == nrOfPlots) delete(nexttile(nrOfPlots)); end
ax.Parent = tcl;
ax.Layout.Tile = sp;
end
if(~isempty(SGtitle)) sgtitle(SGtitle); end
tcl.TileSpacing = 'compact';
% tcl.TileSpacing = 'tight';
tcl.Padding = 'none';
% tcl.TileSpacing = 'none';
% tcl.Padding = 'none';
newFigNr = newFigHandle().Number;
end