Create an index vector defined by two input vectors, one defining the beginnings of one or more index ranges, and the other defining the ends of the ranges.
The difficult part is that for and while loops are disallowed. No looping! [I apologize for the rudimentary regexp test for 'for' 'while' and 'eval'.] My test cases scan for usage of these substrings, so choice of variable names is effectively restricted as well.
So given 2 input vectors x1 and x2, the desired output is a third vector y, containing [x1(1):x2(1) x1(2):x2(2) ... x1(end):x2(end)]
Example:
x1 = [1 5 12]; x2 = [2 8 21];
Result:
y = [1 2 5 6 7 8 12 13 14 15 16 17 18 19 20 21]
Please do not check for the occurance of "for" in general, because "UniFORmOutput" has nothing to do with looping ;-)
Your predefined function signature has only one parameter, altough two were submitted. Same problem without the "for" restriction: http://www.mathworks.com/matlabcentral/cody/problems/555-low-high-low-high-turn-around-create-a-subindices-vector
This is an excellent problem.
I agree with Dirk. Change your regexp to check for instances of eval, for, and while that are not preceded or followed by additional letters.
give me a hint, should we use a specific function here?
'uniformoutpot' is innocent orz~~
'uniformoutput' is innocent orz~~
A separate test case that tests for functions that are against the rules would improve this problem. In this case, the "for" in "UniformOutput" was getting caught by the search. A separate test case would have made clear that the solution functions properly but contains an outlawed string.
Wonderful !
Why x3=[] in the test ?
Nice recursion !
Each solution of Richard is a gem.
Swap the first and last columns
9904 Solvers
735 Solvers
407 Solvers
Flip the main diagonal of a matrix
426 Solvers
124 Solvers