Want to create a vector myOrder(n) from 1:Sum with random values
vec= [1 1 1 1 3 1 4 1 1 5 5]';Sum=sum(vec); for n=1:Sum N=vec(n); if vec(n)==1 myOrder(n) = rand(1); % Condition 1
elseif vec(n)>1 myOrder(n) = (n/(N+1))*(1 + myOffset*randn(1)); % Condition 2
endend
The Problem:
I would like for every iteration in vec:
- The loop subtracts 1 for each value > 1.
- For every new value of vec(n)>1, Condition 2 applies until it reaches the value of 1.
I.e
vec = [1 1 1 1 3 1 4 1 1 5 5]' -> Iteration 1vec = [1 1 1 1 2 1 3 1 1 4 4]' -> Iteration 2vec = [1 1 1 1 1 1 2 1 1 3 3]' -> Iteration 3vec = [1 1 1 1 1 1 1 1 1 2 2]' -> Iteration 4vec = [1 1 1 1 1 1 1 1 1 1 1]' -> Iteration 5
Best Answer