Getting a function error "Output argument "z" (and maybe others) not assigned during call"

2 ビュー (過去 30 日間)
Hey guys im new to matlab ive been trying to do a power function but I've been getting this error and Im not understanding why
Here is the function
function [z] = power1(x,y)
if y>=0
if y==0
z=1;
end
if y==1
z=x;
end
z=x*power1(x,y-1);
end
end

採用された回答

Alexandra Harkai
Alexandra Harkai 2016 年 11 月 1 日
編集済み: Alexandra Harkai 2016 年 11 月 1 日
If y<0, variable z doesn't get any value assigned to it.
See the same question here here.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by