Okay so lets so we had a vector x, filled with random numbers, as an example x could be something like x=[1, 2, 5, 3, 11,] so how could you create a for loop or while loop to multiply each element? so I want to have 1 x 2 x 5 x 3 x 11, or is there another way to do this aside from a for/while loop?? thanks in advance!!!Matlab question!!! just need a lil help/advice?
If you have to use a loop, do this
x=[1, 2, 5, 3, 11]
P = 1;
for k = 1:length(x)
P = P*x(k);
endMatlab question!!! just need a lil help/advice?
You can just use the function prod().
prod(x) returns the product of all the elements of vector x.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment