Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
JBA Miller
JBA Miller el 19 de Mzo. de 2021
Respondida: David Hill el 19 de Mzo. de 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!

Respuestas (1)

David Hill
David Hill el 19 de Mzo. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by