How do I convert all the 'single' type variables in my workspace to 'double'?

4 views (last 30 days)
I need to convert all the 'single' variables in my workspace to 'double'. However, I do not want to use the function DOUBLE on every variable. I would like a small piece of code in my file, that can ensure that all the variables have been set to type 'double'.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2010
The following example demonstrates a way to do this in MATLAB.
s = whos;
for i = 1:length(s)
if strcmp(s(i).class,'single')
name = s(i).name;
assignin('base', name, double(evalin('base', name)));
end
end
This code, upon execution, searches for any 'single' types in the current workspace, and converts them to 'double'.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2008a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!