How to use the simulation time in an embedded function in matlab
3 views (last 30 days)
I am wondering how to correct this simple code in a matlab embedded function included in a simulink file.
function y= hybrid(t, dpo, dic)
if t < 0.04762
In this simple code, "t" would be the simulation time and it is obtained by means of a clock block. However, when I try to compile it, matlab console reports the following error:
"This assignment writes a 'double' value into a 'logical' type. Code generation does not support changing types through assignment. Check preceding assignments or input type specifications for type mismatches. Function 'Hybrid Algorithm/MPPT P&O Function' (#146.60.61), line 6, column 1: "y""
How can I make this simple function work?I have searched for similar questions and applied several advices but with no success.
Thanks a lot.
Walter Roberson on 1 Oct 2022
You are calling hybrid() in a context where through propagation or backwards propagation or explicit setting in the block, or by assignment to the output variable before calling the function... that Simulink has determined that the function is being used in a situation in which the output must be logical but you are returning double instead.
You need to analyze the context in which the function is being called to determine why Simulink thinks the output must be logical.