Determine whether a vector is monotonically increasing in MATLAB


Return true if the elements of the input vector increase monotonically (i.e. each element is larger than the previous). Return false otherwise.

Examples:

 Input  x = [-3 0 7]
 Output  is true
 Input  x = [2 2]
 Output  is false

Code:

clc

x=input('Enter the array:');
t=0;
for i=1:length(x)-1
   m=x(i);
   n=x(i+1);
   if(n>m)
       t=t+1;
   end
end
if(t==length(x)-1)
    disp('True');
else
    disp('False');
end

Explanation:


Output:




No comments