필터 지우기
필터 지우기

How to use the simulation time in an embedded function in matlab

조회 수: 2 (최근 30일)
Manyu Hati
Manyu Hati 2022년 9월 30일
편집: Manyu Hati 2022년 10월 2일
Dear matlabers,
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
y=dpo;
else
y=dic;
end
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.
Manyu
  댓글 수: 1
dpb
dpb 2022년 10월 1일
What are dpo, dic data types and what is the target to which you're trying to assign the result?
I don't know anything at all about Simulink, but my reading says the error says your function needs to return a logical value, not a numeric one.
But, if the two arguments other than t are numeric, then "you can't do that!" because the y value will have to be numeric to hold those values.
What your function could do with these inputs wouldn't have any bearing on what the values of the other two arguments are; but simply return the logic flag
function y= hybrid(t)
y=(t<0.04762)
end
and then you'd need some way to use that result to switch the two inputs to wherever they're supposed to be going.
But, folks would have to see the pertinent parts of the model to have any idea about the total solution.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 10월 1일
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.

추가 답변 (1개)

Manyu Hati
Manyu Hati 2022년 10월 2일
편집: Manyu Hati 2022년 10월 2일
Hi guys,
Thank you for the valuable comments. It seems that the "embedded matlab function block" only treats well numerical variables, but not logical ones. In my specific problem, logical outputs were necessary. However, I managed to treat the variables in the numerical domain by means of this embedded matlab function. After that, I converted them into the logical domain. And in this way, it finally worked!

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by