Simulink error, MATLAB expression '<output of NameOfFunction>' is not numeric.

23 次查看(过去 30 天)
So I have a function with some symbolic variables so I used coder extrinsic to make a matlab function. The output is an array that is 1 by 3. In the matlab function block I take output of the symbolic function and put it through double but it still gives me this error.
I have tried changing it to a double within the symbolic function, but then it says the expected array 3 by 1 not 1 by 3. So I changed the symbolic output to produce a 3 by 1 array and it just comes up with a much larger grosser error. Anyone know anything that can help.
  1 个评论
katherine keogh
katherine keogh 2021-1-13
I am using vpa function now to 10 sf but it still says it is not numeric, even the lines out of the block says it is a double, I'm really confused

请先登录,再进行评论。

回答(1 个)

Imran
Imran 2022-11-25
Hello Katherine,
I understand that you're using 'vpa' function and and not getting the output as a numeric data.
The data type of the output obtained from 'vpa' function is 'sym' which depicts symbolic variable. In order to get double output you need to typecast the output of 'vpa' function to double. For example, take a 3 by 1 array.
x = [1:3]';
p = vpa(x);
% Check the output
disp(class(p)); % = 'sym'
% Typecast it to double
p = double(p);
% Check the data type of the converted output
disp(class(p)); % = 'double'
The above code shows how to get numeric output from 'vpa' function.
I hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by