Problem 10. Determine whether a vector is monotonically increasing
Solution Stats
Problem Comments

37 Comments
I think test 2 is wrong. Is x=0 monotonically increasing? I think not.
I think test 2 is wrong. Is x=0 monotonically increasing? I think not. Why is assertion made against true then?
Does anyone know why this is not working? The code looks chunky, but it should work. Thanks!!
string1 = ['tf is true'];
string2 = ['tf is false'];
tf = diff(x);
w = numel(find(tf==0)) + numel(find(tf<0));
if w > 0
disp(string2)
else
disp(string1)
end
[0] is monotonically increasing, but [0 0 0 0 0] is not. That's messed up. I agree with Kye Taylor.
All solutions with size 11 use the regexp cheat.
[0] isn't going anywhere by definition. It makes no sense that it's 'increasing'.
I agree that [0] should give false by this function, it's not monotonically increasing or increasing at all, right? I also think the test suite should include some vector like [1 2 3 3] that is sorted but not mon. increasing.
Monotonically increasing means that it is never strictly decreasing. [0] is monotonically increasing for this reason, as is any constant vector. This problem should be restated as: Determine if the vector x is "strictly" increasing.
Nice one :D
between 'monotonic' and 'strictly' increasing.
good
Test 3 is incorrect isn't it? By definition, the following is monotonic, and hence also monotonically increasing:
x = [0 0 0 0 0];
One easily understandable size 15 solution is (use rot13 to read it):
shapgvba gs = zbab_vapernfr(k)
gs = vfrdhny(k, havdhr(k));
raq
nice
Good question
for i= 1:(length(x)1)
if (x(i)< x(i+1))
disp('true');
else
disp('false');
end
end
it is providing correct result in my pc but not accepting here
@Sankari Name, Dawg, replace "disp('false')" and "disp('true')" with "tf=false" and "tf=true" respectively. see below,
x=[0]
for i= 1:(length(x)1)
if (x(i)< x(i+1))
tf=true
else
tf=false
end
end
but your code wont pass the test where x=[0]
The [former] second test case of x = [0] has been removed due to its tendency to cause confusion.
Also, the test case with x = [0 0 0 0 0] has been removed since it was originally marked as false. Technically, a monotonic function "is either entirely nonincreasing or nondecreasing" per Wolfram.com. Per this definition, that answer should have been true, as it would also be true for monotonically decreasing.
nice
can someone explain to me why this code is not good for this problem
function tf = mono_increase(x)
for i:1:(length(x)1)
if x(i+1) > x(i)
tf = "true"
else
tf= "false"
end
end
end
@Ongun Palaoglu:
#1, you are returning strings of true and false instead of true or false values. Do not use " in the solution.
#2, you are returning a true or false value for each comparison, with each prior result being overwritten. Only the last value will be returned by the function.
Single line solution.
a little bit difficult
function tf = mono_increase(x)
tf = false;
for ii=2:length(x)
if x(ii1)< x(ii)
tf=true;
end
end
end
why i have 2 assertion errors i don't get it?what i's wrong
@Gizem, because your code only a partial condition of what is asked.
interesting one
basic algebra question.
I can't use diff function becasue it contain 'if'. What the hell
@Xingkai, that issue has been resolved and your solutions have been rescored.
Why is elseif banned? There is nothing it can accomplish that if cannot.
@Brandon People unfortunately abuse if/elseif to hardcode solutions for the test suite instead of actually solving problems. That said I agree with you that outright banning these language constructs in the test suite is almost always excessive.
I thought this one was tricky.
Great Problem
The code is to useful and helped me in learning new things
Great problem
great problem
Solution Comments
Show commentsProblem Recent Solvers20154
Suggested Problems

2564 Solvers

1998 Solvers

Determine the number of odd integers in a vector
706 Solvers

Find last zero for each column
514 Solvers

960 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!