Why I cannot get negative answer ?
Ältere Kommentare anzeigen
clear all; close all; clc;
x = input('x= ');
y = input('y= ');
if (x>=5) & (y>2)
f(x,y)=x^2-y;
elseif (x<5) | (y>0 & y<=2)
f(x,y) = x-y^2;
else (x<0 & x>0) & (y<0)
f(x,y)= x^3 + y^3;
end
f(x,y)
%when I try input x =0 and y=2 it does not run
%Index in position 1 is invalid. Array indices must be positive integers or logical values.
%How to I solve that?
%Thank you very much
1 Kommentar
clear all; close all; clc;
x = 0 ;
y = 2 ;
if (x>=5) & (y>2)
f = @(x,y) x^2-y; % define function using function handle
f(x,y)
elseif (x<5) | (y>0 & y<=2)
f= @(x,y) x-y^2;
f(x,y)
else (x<0 & x>0) & (y<0)
f = @(x,y) x^3 + y^3;
f(x,y)
end
Define the function using its function handle as the way you try to call function
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!