フィルターのクリア

Vector type output from MATLAB function in Simulink - Errors

16 ビュー (過去 30 日間)
patr chri
patr chri 2020 年 5 月 27 日
編集済み: patr chri 2020 年 5 月 28 日
Hello all,
I have been trying to work out how to implement a vector of any size (1xn) with MATLAB functions in Simulink. For the purposes of this question, let's take a simple test model found in the attached image.
In the first MATLAB function, I have the following simple code:
function y = fcn(u)
if(u == 1)
a = zeros(1,6);
y = a;
end
end
In the second MATLAB function, I have the following code:
function k = fcn(u1)
if(u1(1) == 0)
k = 2;
end
end
Based on answers on relative previous questions in the forum, I have the following settings regarding the variables in both MATLAB function:
However, I get the following errors when I try to run the model:
Output argument 'k' is not assigned on some execution paths.
Function 'MATLAB Function1' (#2181.9.10), line 1, column 10:
"k"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'untitled/MATLAB Function1'
Component:MATLAB Function | Category:Coder error
Output argument 'y' is not assigned on some execution paths.
Function 'MATLAB Function' (#2174.9.10), line 1, column 10:
"y"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'untitled/MATLAB Function'
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'untitled/MATLAB Function'
Component:Simulink | Category:Model error
Any ideas what I am doing wrong?
Thanks,
Christos

採用された回答

patr chri
patr chri 2020 年 5 月 27 日
編集済み: patr chri 2020 年 5 月 28 日
The issue was that I hadn't declared an else/elseif in the if statement so Simulink didn't know what to do if the statement wasn't applying.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModel, Block, and Port Callbacks についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by