setvartype does not work
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Guillaume
2019-7-3
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!