how can I declare a persistent variable as single precision?

17 ビュー (過去 30 日間)
LiAS
LiAS 2016 年 4 月 11 日
コメント済み: Walter Roberson 2016 年 4 月 11 日
Hi, I develop in matlab functions there is a simulator which is developed in simulink which calls a function in matlab. I get the parameters values from Simulink as singles I need to declare my variables in singles too , is it possible to change the default in matlab (not simulink)as singles instead of double? the big problem is that I didnt succeed to change the persistent variables to singles, thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 4 月 11 日
For MS Windows only, there is an undocumented feature() call that can cause variables to default to single precision. It cannot, however, be applied to a single variable, and using it almost always causes nasty problems.
If you want to be sure a variable is stored as single precision in MATLAB, then make sure it is in single precision, either through computation path or by using single() on the expression, such as
MyPersistentVariable = single(SomeExpression);
  2 件のコメント
LiAS
LiAS 2016 年 4 月 11 日
編集済み: Walter Roberson 2016 年 4 月 11 日
thanks,
the problem is with the persistent variables
can you write this more specific
I wrote:
persistent MyPersistentVariable ;
% how can I declare it as single?
if isempty(MyPersistentVariable )
MyPersistentVariable =0; % suppose here it's too late
end
Walter Roberson
Walter Roberson 2016 年 4 月 11 日
persistent MyPersistentVariable ;
if isempty(MyPersistentVariable )
MyPersistentVariable = single(0.0);
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by