From: doug kopet on
thanks my friend,

i got the answer in your code by jus making small change to the code u suggested.

--> result_part = MM(startingRow:3:end, :) * BB(startingRow,:)'

Can I ask you how to get all the result_part's to store into a single matrix after the looping has finished.

doug
From: Roger Stafford on
"doug kopet" <onedougk(a)gmail.com> wrote in message <i3vdpl$dn0$1(a)fred.mathworks.com>...
> Hi everyone,
>
> I'm a new matlab user and new to programming and would like to request some help.
>
> I have 2 matrices MM and BB:
>
> MM = [ 1 2 2 ;
> 5 3 6 ;
> 9 8 7;
> 8 8 4 ;
> 6 1 1 ;
> 5 0 5 ]
>
> BB = [ 31 32 44 ; 20 17 33; 19 44 22]
>
>
>
> I would like to multiply in the following manner using a looping procedure :
>
>
> result_part1=[1 2 2; 8 8 4] * [ 31 32 44]'
>
> result_part2 = [ 5 3 6 ; 6 1 1] * [ 20 17 33]'
>
> result_part3 = [9 8 7; 5 0 5]* [19 44 22]'
>
>
>
> Then, I would like to output them in the following manner:
>
> final_answer = [ 183 349 677; 680 170 205]
>
> cheers
> doug
- - - - - - - - - - - -
Try this:

p = size(MM,1)/size(BB,1);
final_answer = reshape(sum(MM.*repmat(BB,p,1),2),[],p).';

The two requirements for this generalization are that size(MM,2)=size(BB,2) and size(MM,1) be an integral multiple of size(BB,1).

Roger Stafford
From: doug kopet on
dont bother,i got it with the indexing