setvartype does not work
3 views (last 30 days)
Show older comments
Sebastian Starke
on 3 Jul 2019
Commented: Sebastian Starke
on 3 Jul 2019
Hello,
i need to convert a workspace variable or even a struct with several variables from standard double to single. This is needed because i use simulink coder for codegen and want to make these parameter variables globally accessable from the code environment. Release is 2018a.
I found the expression:
opts = setvartype(opts,type)
in the documentation, but it won't work. It seems to be a basic function, nevertheless I get the following error-message:
>> density = setvartype(density,'double')
Undefined function or variable 'setvartype'
Am i doing something wrong?
0 Comments
Accepted Answer
Guillaume
on 3 Jul 2019
As it says on the 3rd line of the documentation, opts = setvartype(opts,type) "updates all the variables in the opts object ...". Said opts object being an object returned by detectImportOptions. The whole purpose of detectImportOptions and setvartype is to customise the import of text (or excel) files, nothing else.
The way to convert a variable to double, if it's not already (bearing in mind that's the default), is with:
density = double(density);
Whether or not it will solve your actual problem, I have no idea as I don't use Simulink or coder. If it doesn't you would be better off asking in a new question how to solve your actual problem which is how to make parameters globally accessible whatever that means. You probably need to give more details.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!