Interpreted Matlab function error
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello all,
I'm building a Simulink model in which I have to implement some differential equations. I created a matlab function which takes some inputs and performs the needed operations. My syntaxe is:
function dx=test(x)
%%some variables
...
%%equations
dx1 = ...
dx2 = ...
...
dx11 = ...
dx=[dx1;dx2;dx3;dx4;dx5;dx6;dx7;dx8;dx9;dx10;dx11];
end
However, when running it in Simulink, it returns me the error: Evaluation of expression resulted in an invalid output. Only finite double vector or matrix outputs are supported.
The really weird part is: when I go to Matlab's Command Window and:
1) Run the exact same code lines: It works and I receive dx as a vector of eleven finite values, exactly as expected.
2) Call the function by its name, passing the correct inputs: I receive ans = [] and the variable dx is not even declared;
Does anyone have an idea of what might possibly be the cause?
Thank you in advance.
6 comentarios
Stephen23
el 25 de Mayo de 2018
Once again globals cause problems that are hard to debug. So no surprises there.
@Pedro Seger: avoid using global variables (this is the best advice you will get on them). There are much better (neater, faster, easier to debug) ways of passing data between workspaces, e.g. parameterized functions or nested functions. See:
Ting Liang
el 25 de Mzo. de 2021
Hi Stephen,
Excuse me.
I encountered the same problem now, I tried your methods, but it didn't work, could you please give some clues? Thanks. The problems are described as follows:
In simulink, I used the interpreted MATLAB function, to call for HEX_LT function, it works.
But if there is a subfunction (like SFHC) within the HEX_LT function, shown as follows:
function y = HEX_LT(para)
hex = SHFC (Pa_in, Ga, Qw, di, Tb);
Uo = 1/(1/ho + do^2 /(hex(i)* di^2));
... y = T;
end
I have tried several ways, but all didn't work, all told me that ' Evaluation of expression resulted in an invalid output. Only finite double vector or matrix outputs are supported', could you please help with this?
Thanks, and looking forward to your reply.
Respuestas (0)
Ver también
Categorías
Más información sobre Simulink Environment Customization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!