Using if statement inside a function,I didn't understand why the error is coming,why I am unable to use the values of x & y inside the if loop

4 次查看(过去 30 天)
function O = help(~,~)
i=input('Value of i:');
j=input('Value of j:');
O = y(i,j);
function g=y(x,y)
if(x==y)
{
k = rem(x,2);
s = log2( (y - k) );
g = 2^(-s);
}
else
{
g=0;
}
end
return;
end
return;
end
  2 个评论
Walter Roberson
Walter Roberson 2013-3-11
There is no such thing as an "if loop". The body of an "if" is executed exactly once (or not at all), whereas a "loop" would continue executing the body until some condition was met.
Jan
Jan 2013-3-11
Please post the error message.
Be sure not to shadow the important Matlab function help by your function. This would be a very bad idea.

请先登录,再进行评论。

采纳的回答

Vishal Rane
Vishal Rane 2013-3-11
Curly braces for the if-else statement are not required.
  3 个评论
Jan
Jan 2013-3-11
As Vishal Rane has said already: remove the curly braces in the IF-block. They are not only not required, but even an error, because curly braces create a cell array.
Raviteja Panamgipalli
Thank you,I forgot that matlab doesn't need curly braces for if else statement,confused with C programming,Anyway thankyou both for your suggestions Vishal & Walter Roberson

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by