Effacer les filtres
Effacer les filtres

How to get average of certain cells in a three dimensional table?

2 vues (au cours des 30 derniers jours)
JBA Miller
JBA Miller le 19 Mar 2021
Hi!
I have a 61x2x1000 double which gives me the results of 1000 simulations for stock prices of 61 consecutive months. This is for two different stocks, why the third dimension here is 2.
How do I get to the average stock price of one stock for each month? Or let's say the average for every second month price for stock 1 of all the 1000 trials?
Thanks!

Réponses (1)

David Hill
David Hill le 19 Mar 2021
Average price of stock each month.
stockA=zeros(1,61);
stockB=zeros(1,61);
for k=1:61
stockA(k)=mean(yourMatrix(k,1,:));
stockB(k)=mean(yourMatrix(k,2,:));
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by