Note that this will fail on a short sequence e.g. [10 20 21 40]
I believe changing mode to median should work in all non-ambiguous cases (length>3)
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%% test 1
nterms = 10;
term0 = randi(10);
increment = (-1)^randi(2)*randi(10);
correctsequence = term0:increment:term0+(nterms-1)*increment;
for position = 1:nterms
errorsequence = correctsequence;
errorsequence(position) = errorsequence(position) + (-1)^randi(2)*randi(50);
[errorposition, truesequence] = find_error(errorsequence);
assert(errorposition == position && isequal(truesequence, correctsequence), 'failed test 1 at position %d', position);
end
|
2 | Pass |
%%test 2
nterms = 201;
term0 = randi(10);
increment = (-1)^randi(2)*randi(10);
correctsequence = term0:increment:term0+(nterms-1)*increment;
for position = 1:10:nterms
errorsequence = correctsequence;
errorsequence(position) = errorsequence(position) + (-1)^randi(2)*randi(50);
[errorposition, truesequence] = find_error(errorsequence);
assert(errorposition == position && isequal(truesequence, correctsequence), 'failed test 2 at position %d', position);
end
|
Make the vector [1 2 3 4 5 6 7 8 9 10]
35550 Solvers
Sort a list of complex numbers based on far they are from the origin.
4327 Solvers
Convert a numerical matrix into a cell array of strings
455 Solvers
464 Solvers
Multiples of a Number in a Given Range
214 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!