Saving data in a loop into a vector (values are not integers)
Afficher commentaires plus anciens
Hello Everyone,
I am facing a little problem and would be very thankful if you can help me with it.
I have a function to calculate a stock price. It can loop up to 40 times to get the final price. I wanted to simulate the function and came into two problems:
1- I added a new variable, say x, that stands for the number of simulations. Now, at the beginning of the function, if x > 0, the main algorithm starts and loops over until x = 0. The problem is when it comes to saving the different stock prices at each run. Suppose x = 5, then I have 5 stock prices which I can see in Matlab command window. Suppose the prices "S" are [100.5 101.3 99.80 97.6 102.3], I can see it as: S = 100.5 ..... S = 102.3 but I want to save them all in one vector; I couldn't use y(S) as S is not an integer! any suggestions?
2- I was aiming to do some big simulation with the model, but noticed that I reached the recursion limit. Since up to 40 loops are required at each simulation/ do you think it is still possible to achieve this goal, say with 10,000 simulations? if yes, any initial guidance for this?
Thanks & Best Ali
4 commentaires
Azzi Abdelmalek
le 3 Jan 2013
What have you done so far?
2- I was aiming to do some big simulation with the model, but noticed that I reached the recursion limit. Since up to 40 loops are required at each simulation/ do you think it is still possible to achieve this goal, say with 10,000 simulations? if yes, any initial guidance for this?
Clarify the connection between loops and recursion. Does each of the 40 loops initiate a recursive call? Even if so, why would you reach the recursion limit (default = 500) when each simulation requires only 40 recursions.
Thanks for the point, it should have been clarified. The main 40 loops don't call for recursive call, but if I set x, the number of simulation, to any value above 25; that is above 25 simulations of the model which contains the 40 loops, then there will be a recursive call.
There's still no way we (those of us who have never seen your code) can understand why that occurs or why we should expect it to break the recursion limit.
Réponse acceptée
Plus de réponses (1)
What does the code that generates S look like? You should change it to something that does this
S(1) = 100.5 ..... S(5) = 102.3
1 commentaire
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!