Does Simulink have an issue with typecasting in Matlab function blocks?

7 ビュー (過去 30 日間)
Dean DeBastiani
Dean DeBastiani 2019 年 10 月 3 日
I have a function that initializes a vector of uint32s to some arbitray size and then typecasts the vector of uint32s to bytes (uint8s). When I do this the simulink system has an error. 'Inferred size of ('[100]') for data blah blah does not match the specified size ('[200]')'. The initialized size of the uint32 is a constant. The vector of uint8's is based on the vector of uint32s with respect to size. It seems that when I use the typecast function, even though the vector of uint32s is specified as uint32s, it typecasts them as doubles. My reasoning for that statement is, if I typecasted a vector of 25 uint32s, the resulting uint8 vector would be a dimension of 100, but if the original vector was 25 doubles, the resulting size would be 200. I have tried specifing sizes in the matlab function blocks and working with variable sizes, but have not found a fix. This only happens when trying to do a diagram update in simulink (Ctrl + D) with the system propagation. So, I do not see the error when I run the same functionality with scripting. Has any else ran into issues with typecasting in simulink? See functions used below.
vecUint32 = uint32(zeros(25, 1));
vecUint8 = typecast(vecUint32, 'uint8');
  1 件のコメント
Taylor Hillegeist
Taylor Hillegeist 2020 年 4 月 14 日
I just ran into this recently. In order to change the input type of a Matlab Function you have to go throught the Model Explorer to change the type for the input and output. It was super frustrating, becasue trying to change the port options for the function didn't link to these properties but the signal properties for the input.

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

回答 (1 件)

Praveen Kumar Pakkiri Samy
Praveen Kumar Pakkiri Samy 2020 年 8 月 6 日
I faced this problem recently.However, I fixed it by changing the size of the output function. You can follow the steps below.
  1. Go to the function
  2. Click edit data on the top (right to the Run Model button)
  3. Click on your output and set the size to 1.
  4. Run the simulink model
I hope it works for you. Good Luck!!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by