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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 11 Mär. 2013
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
am 11 Mär. 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.
Akzeptierte Antwort
Vishal Rane
am 11 Mär. 2013
Curly braces for the if-else statement are not required.
3 Kommentare
Jan
am 11 Mär. 2013
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!