Random numbers generation based on specific distribution function, then sort in specific way
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I would like to generate random numbers based on some distribution function in Matlab. After generating numbers, sort them in a specific way. For example, during rush hour, the demand for taxis is high. Thus, after the generation of demand numbers, put the highest number in the specific time, and then sort other numbers from the highest number.
For instance:
(t=1) 10;
(t=2) 12;
(t=3) 16;
(t=4) 21;
(t=5) 25;
(t=6) 22;
(t=7) 18;
(t=8) 15;
(t=9) 11;
(t=10) 7
Finally, export data to Excel.
0 Commenti
Risposte (2)
the cyclist
il 8 Giu 2023
Do you need the highest numbers in the specific time (and decreasing away from there) always, or just statistically? Drawing numbers from a Poisson distribution will have this property in the long run, but not necessarily for every possible draw. For example:
rng default
t = poissrnd(6,157,1);
histogram(t)
You can see that there are more 9's than 8's. But on average there will be more 8's than 9's. This type of randomness is what will more typically observed in the real world. But I don't really know what you need.
(Out of curiosity, is this a school assignment? Sounds like a school assignment.)
John D'Errico
il 8 Giu 2023
Modificato: John D'Errico
il 8 Giu 2023
Where is the problem?
- You don't say what the distribution of those numbers is, so absolutely nothing can be done until you decide WHICH distribution they come from.
- Once you know the distribution, then generate them. Again, what is the problem? There are many tools in MATLAB that can be used to generate random numbers, so rand, randi, randn, and then over a dozen more in the stats toolbox.
- Then you need to sort them. Use sort. Again, what is the problem? You don't say what the criteria for how this sorting should work, only somethign vague.
- Finally, you need to export them. A better suggestion is to learn MATLAB sufficiently well that you can just work in MATLAB. If your goal is to work in Excel, then there are random number gneeration tools in Excel too, so just work there, and don't bother with MATLAB.
Break a large problem for you into small problems. Learn to solve each small problem, then put it all together.
3 Commenti
the cyclist
il 8 Giu 2023
If we set aside all additional, irrelevant information you provided, it seems like your question is, "Given a list of numbers, how can I sort them so that the largest is at a specified index, and then progressively smaller in both directions?"
For example, how to go from
x = [17 2 3 5 11 7 13];
to
xs = [3 7 13 17 11 5 2];
Can I suggest that you post a new question, asking just that, without the distracting info. You will get more people looking at a new question.
Vedere anche
Categorie
Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
