Interpreted Matlab function error
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
Ameer Hamza
el 25 de Mayo de 2018
If possible, attach the actual function to the question. I will be easy to spot the issue. Otherwise, you can use MATLAB debugging options to spot the problem inside the function https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html.
Stephen23
el 25 de Mayo de 2018
"Does anyone have an idea of what might possibly be the cause?"
Possibly a bug in the code, or how it is being called. But without the code we cannot say much more than this. If you want help with this, please upload the function by clicking the paperclip button.
Pedro Seger
el 25 de Mayo de 2018
Guillaume
el 25 de Mayo de 2018
However, it escapes me how the global variables were not found by the function
That's one of the many reasons why global variables are to be avoided like the plague. It's very difficult to keep track of their state which leads to subtle and very hard to debug behaviour.
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)
Categorías
Más información sobre Simulink Environment Customization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!