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

4 visualizzazioni (ultimi 30 giorni)
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!

Risposte (1)

David Hill
David Hill il 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

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by