Greetings All
I have an array
[1 2
3 4
5 6]
I'm trying to get entire columns to multiple together using recursion
but I'm having trouble with the logic.
Example: the array above should come back with
[15 48] which is (1*3*5) and (2*4*6)
I attempted to do this using a matlab for loop but no luck as of yet.
Does anyone know the correct logic?
xarray=[1 2;3 4;5 6];
multiply=0;
[rowSize,colSize]=size(xarray);
for cc=1:colSize,
for rr=1:rowSize,
multiply(1,cc)=multiply(rr,cc)*xarray(rr+1,cc);
end;
end;
tia sal22
Assuming this isn't homework, you don't need to use recursion. Just use the
PROD function with the dim input argument to specify that you want to
multiply down the columns.
> I attempted to do this using a matlab for loop but no luck as of yet.
You could also do this with one FOR loop, appropriate indexing to extract
rows of your matrix, and the .* operator.
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ