The domain for Matlab to choose from is always decreasing

8 vues (au cours des 30 derniers jours)
Dipesh
Dipesh le 29 Oct 2012
Lets say I start off with a set number of N = 100. I have created a graph that goes along the x axis a random time, then randomley jumps or down 1 and then carries on.
In this graph, Matlab can essentially choose from any number within the interval [0,100] and can keep running on a loop over and over agai. What I want is that after it randomley jumps up or down 1, N = N - 1. So eventually you will get that N = 1 and the only option is for it to drop down 1 to 0. How do I do this?

Réponses (1)

Sean de Wolski
Sean de Wolski le 29 Oct 2012
You could use a for-loop and randperm to do this:
result = zeros(100,1);
for ii = 1:100
result(ii) = randperm(ii,1);
end

Catégories

En savoir plus sur Networks dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by