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

6 views (last 30 days)
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 Comments
Jan
Jan on 11 Mar 2013
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.

Sign in to comment.

Accepted Answer

Vishal Rane
Vishal Rane on 11 Mar 2013
Curly braces for the if-else statement are not required.
  3 Comments
Raviteja Panamgipalli
Raviteja Panamgipalli on 11 Mar 2013
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!