Borrar filtros
Borrar filtros

For loop for this ?

1 visualización (últimos 30 días)
Hannes Arnar
Hannes Arnar el 1 de Abr. de 2020
Respondida: David Hill el 2 de Abr. de 2020
Vcd{1} = 125 *(1+rr{1}); %Investment in company
Vcdd{1} = Vcd{1}.*(1+rr{2});
Vcde{1} = Vcdd{1}.*(1+rr{3});
%% rr are cell are that includes returns for time periods
  2 comentarios
David Hill
David Hill el 1 de Abr. de 2020
A better description of what you are trying to do would help. Why do you have so many cell arrays?
Hannes Arnar
Hannes Arnar el 2 de Abr. de 2020
Let's say I have 3 stocks, with annual asset return (rr) = 0.2 , 0.3, 0.4 and the investment in the stock are 125 dollars per each stock.
So I want to creata a loop that calculates the Investment so for the first years it would be:
year 1 : 125 * 0.2 , 125 * 0.3 , 125 * 0.4
year 2: new value * 0.2 , new value * 0.3, new value * 0.4
year 3 : new value1 * 0.2, new value1 * 0.3, new value1 * 0.4

Iniciar sesión para comentar.

Respuestas (1)

David Hill
David Hill el 2 de Abr. de 2020
A simple matrix would work much better.
Vcd=125*(ones(3,10).*[1.2,1.3,1.4]').^(1:10);%this is 10 years, each column with the different rates for the year

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by