How can I loop with two variables, can't figure it out
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I am totally new to Matlab, and my master thesis require me to use matlab to do some analysis. I had a problem with loop. I wanna construct a loop with two variables for example
for i = 2:4
for j = 1:4
Ratio = Price(i,:)/Vol(j,:)
end
end
Price = 1 2 3 4
5 6 7 8
9 8 9 6
Vol = 2 3 4 5
6 7 8 9
1 2 3 4
and I want my answer to be
ratio = 2.5 2.0 1.8 1.6
1.5 1.1 1.1 0.7
The 2nd row of Price divide by the 1st row of Vol The 3rd row of Price divide by the 2st row of Vol and so on ...........until the end row of price then stop the loop.
Can it work if price and Vol has different number of row but they have some number of Column?
2 Commenti
Stephen23
il 25 Gen 2015
Note that you should not use the variable names i and j, as these are the names of the inbuilt imaginary unit.
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!