Creating a persistent variable type single

6 ビュー (過去 30 日間)
Terry Sherman
Terry Sherman 2011 年 4 月 25 日
Suppose I want to create a persistent variable but I wanted that variable's data type to be a single. By default MATLAB creates doubles. How can I have them be singles?
(As a background I am using Simulink to model a plant and its controller. I am using Embedded MATLAB as the code for the controller. I want the data types to mimic the data types in the final DSP I'll use in my product. So I want the Embedded MATLAB to run using the single rather than double)
I have tried the following but it does not work:
persistent Accumulated_I_Error;
if isempty(Prev_Line_Voltage_ADC)
Accumulated_I_Error = single(0);
end
...
Accumulated_I_Error = a + b;
...
I receive a compile error of: Class mismatch (single ~= double). The class to the left is the class of the left-hand side of the assignment.

回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 4 月 25 日
What classes are a & b?
Does the error occur on that line?
  1 件のコメント
Terry Sherman
Terry Sherman 2011 年 4 月 25 日
The error occurs on the line Accumulated_I_Error = single(0); I was hoping that the data types of 'a & b' are irrelevant if I declared the type of Accumulated_I_Error. I am in the process of casting a & b to see if that matters.

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

カテゴリ

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