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

36 vues (au cours des 30 derniers jours)
katherine keogh
katherine keogh le 12 Jan 2021
Réponse apportée : Imran le 25 Nov 2022
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 commentaire
katherine keogh
katherine keogh le 13 Jan 2021
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

Connectez-vous pour commenter.

Réponses (1)

Imran
Imran le 25 Nov 2022
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