Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

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

Popular Posts