Does Simulink have an issue with typecasting in Matlab function blocks?
7 views (last 30 days)
Show older comments
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 Comment
Taylor Hillegeist
on 14 Apr 2020
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.
Answers (1)
Praveen Kumar Pakkiri Samy
on 6 Aug 2020
I faced this problem recently.However, I fixed it by changing the size of the output function. You can follow the steps below.
- Go to the function
- Click edit data on the top (right to the Run Model button)
- Click on your output and set the size to 1.
- Run the simulink model
I hope it works for you. Good Luck!!
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!