-
Notifications
You must be signed in to change notification settings - Fork 6
/
double2single.m
58 lines (46 loc) · 2.37 KB
/
double2single.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
function ds = double2single(ds)
% ds = data structure
for n=1:length(ds)
fnames = fieldnames(ds(n));
for f=1:length(fnames)
% diving down one more level of the structure
if eval(sprintf('isstruct(ds(%.f).%s)',n,fnames{f}))
xds = eval(sprintf('ds(%.f).%s',n,fnames{f}));
for xn=1:length(xds)
xfnames = fieldnames(xds(xn));
for xf=1:length(xfnames)
% diving down one more level of the structure
if eval(sprintf('isstruct(xds(%.f).%s)',xn,xfnames{xf})) %% is struct
yds = eval(sprintf('xds(%.f).%s',xn,xfnames{xf}));
for yn = 1:length(yds)
yfnames = fieldnames(yds(yn));
for yf=1:length(yfnames)
if eval(sprintf('isa(yds(%.f).%s,''double'')',yn,yfnames{yf}))
eval(sprintf('yds(%.f).%s = single(yds(%.f).%s);',yn,yfnames{yf},yn,yfnames{yf}))
end
end
end
elseif eval(sprintf('iscell(xds(%.f).%s)',xn,xfnames{xf})) %% is cell
yds = eval(sprintf('xds(%.f).%s',xn,xfnames{xf}));
for yn = 1:length(yds)
yds{yn} = single(yds{yn});
end
else
if eval(sprintf('isa(xds(%.f).%s,''double'')',xn,xfnames{xf}))
eval(sprintf('xds(%.f).%s = single(xds(%.f).%s);',xn,xfnames{xf},xn,xfnames{xf}))
end
end
end
end
elseif eval(sprintf('iscell(ds(%.f).%s)',n,fnames{f})) %% is cell
xds = eval(sprintf('ds(%.f).%s',n,fnames{f}));
for xn = 1:length(xds)
xds{xn} = single(xds{xn});
end
else
if eval(sprintf('isa(ds(%.f).%s,''double'')',n,fnames{f}))
eval(sprintf('ds(%.f).%s = single(ds(%.f).%s);',n,fnames{f},n,fnames{f}))
end
end
end
end