MATLAB: How to make coupled data

coupled datamultiply each column

Dear all,
I have two matrices precipitation and temperature data:
A = rand(101078,16);
B = rand(101078,12);
I want to calculate each column of them together so I will have 192 data, for example:
A(:,1)*B(:,1);
A(:,1)*B(:,2);
A(:,1)*B(:,3); ...
A(:,2)*B(:,1);
A(:,2)*B(:,2);
A(:,2)*B(:,3); ...
Does anyone know about how to simply compute them?
Thanks. Handriyanti

Best Answer

  • Array preallocation and two loops will do the trick:
    A = rand(101078,16);
    B = rand(101078,12);
    %
    C = NaN(size(A,2),size(B,2));
    for a = 1:size(A,2)
    for b = 1:size(B,2)
    C(a,b) = A(:,a).' * B(:,b);
    end
    end
    Giving this output:
    >> numel(C)
    ans = 192
    >> C(1)
    ans = 2.5359e+004