Output argument "variable" (and maybe others) not assigned during call to "function".

I'm new to MATLAB and have created a simple function. However, matlab shows me the following error: Output argument "val" (and maybe others) not assigned during call to "u".
Here is the code:
function val = f(n)
val = u(n) - u(n - 4);
end
Here is u(x):
function val = u(x)
if x < 0
val = 0;
end
if x == 0
val = 0.5;
end
if x > 1
val = 1;
end
end

1 件のコメント

Stephen23
Stephen23 2018 年 3 月 30 日
The possibility that x is non-scalar should also be considered. This code would be much improved by being written completely vectorized.

サインインしてコメントする。

 採用された回答

James Tursa
James Tursa 2018 年 3 月 30 日
編集済み: James Tursa 2018 年 3 月 30 日
Your code is calling a function named "u" and that function is not returning a value, so nothing gets assigned to val. What does the code for your "u" function look like? Or is "u" supposed to be a variable?
EDIT:
Your "u" function does not assign anything to the val output if the input x is between 0 and 1. So maybe you need to make that last test
if( x > 0 )

1 件のコメント

Satyam Singh
Satyam Singh 2018 年 3 月 30 日
Ahh, it was supposed to be x>0 only..Oops.. It solved my problem thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by