How to covert ALL "double" values into "single" in MATLAB?
In my matlab workspace I have structs, cells and variables . In need to convert all "double" type values into "single" type values.
For example from
4x33 double
I need to make it to
4x33 single
I have already used such piece of code:
s = whos;
disp(s)
for i = 1:length(s)
if strcmp(s(i).class,'double')
name = s(i).name;
disp(name);
assignin('base', name, single(evalin('base', name)));
end
end
And it works fine for variables which are stored in my workspace, but issue is that it cannot reach values which are stored in workspace in structs.
How can I achieve that?
The way to convert a double to single is
b=single(a)
.
You can use single
as a structfun:
a.c=5;
b=structfun(@single,a)