Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

why did i receive these errors during developing a simple code in Mat-lab function block?

조회 수: 3 (최근 30일)
function [y1, y2, y3, y4, y5]= abs(u1)
%#codegen
if u1 < 48.2
y1 = 1
if u1 < 48.2
y3 =0
elseif u1 < 48.2
y4 =0
elseif u1 < 48.2
y5 =0
else
return
end
elseif u1 >= 51.8
y2 =1
else
return
end
end
% #received errors are:
1. Output argument 'y1' is not assigned on some execution paths.
Function 'MATLAB Function1' (#24.31.34), line 1, column 32:
"abs"
Launch diagnostic report.
2. Errors occurred during parsing of MATLAB function 'MATLAB Function1'(#23)
3. Code Directory :
"D:\myproj\slprj\_sfprj\rehearsal\_self\sfun\src"
Machine (#22): "rehearsal" Target : "sfun"
  댓글 수: 1
Stephen23
Stephen23 2015년 9월 2일
Never call your function abs, because this is the name of the extremely commonly used inbuilt abs function. For the same reason you should never use the names length, size, i, j, cell, etc. etc.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 2일
Unless u1 < 48.2 you do not assign any value to y1.
In MATLAB, you do not always have to assign to all possible outputs, but if you do assign to an output you should always have assigned to all outputs to the "left" of it in the list of outputs.
You appear to be using Simulink. You should probably be assigning to all possible outputs anyhow.
  댓글 수: 1
ahmed al-kady
ahmed al-kady 2015년 9월 2일
yes, i am using simulink and all outputs are assigned to certain blocks however this error appear.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by