Creating a column vector by multiplying the n-1 element by the corresponding element in another vector
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hannah
am 10 Okt. 2013
Beantwortet: Roger Stafford
am 10 Okt. 2013
Hello,
I am quite new to matlab so I am hoping this is a simple question. I am trying to create a column Vector (M) where the first element is known (e.g. 1) and then subsequent elements are calculated by multiplying the above element in vector M (x-1) and the corresponding element in another vector (F)(y).
For example:
F=[2;3;4;5;6)
I want M to represent the following
M=[1;3;12;60;360]
I guess it would be something along the lines..
M=[1;M(1,1).*F(2,1);M(2,1).*F(3,1);M(3,1).*F(4,1);M(4,1).*F(5,1)
Am i on the right track?
0 Kommentare
Akzeptierte Antwort
Roger Stafford
am 10 Okt. 2013
You don't need to use a for-loop for this problem. Let the first known element of M be 'a'.
M = cumprod([a;F(2:end)]);
0 Kommentare
Weitere Antworten (3)
Azzi Abdelmalek
am 10 Okt. 2013
F=[2;3;4;5;6]
n=numel(F)
M=zeros(n,1);
M(1)=1;
for k=2:n
M(k)=M(k-1)*F(k);
end
disp(M)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!