-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfigConvert.m
More file actions
78 lines (66 loc) · 2.08 KB
/
figConvert.m
File metadata and controls
78 lines (66 loc) · 2.08 KB
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
73
74
75
76
77
78
function [newFigNr] = figConvert(figNr, subplotDim1Dest, subplotDim2Dest, subplotDim1Source, subplotDim2Source)
% 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)
subplotDim1Dest = 2;
subplotDim2Dest = 3;
end
if(nargin == 3)
subplotDim1Source = subplotDim1Dest;
subplotDim2Source = subplotDim2Dest;
end
nrOfPlots = subplotDim1Dest*subplotDim2Dest;
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(subplotDim1Dest, subplotDim2Dest);
% tcl = tiledlayout('flow')
for( sp = 1:nrOfPlots)%numel(h.Childrens)
figure(figNr); subplot(subplotDim1Source, subplotDim2Source, 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 && sp ~= 1) 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