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

 采纳的回答

Stephen23
Stephen23 2017-1-30
编辑:Stephen23 2017-1-30
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

3 个评论

The size of the matrix become 192x192. Is there any possibilities to get 101078x192 matrix after multiplying them?
@Handriyanti Diah Puspitarini: the output matrix is not 192x192. It is easy to check its size:
>> size(C)
ans =
16 12
which gives 192 elements. Your question requested 192 elements: "so I will have 192 data"
If you do not what "192 data", what do you want? Please be more specific because I cannot read your mind. Note that your original question gives the example A(:,1)*B(:,1), but this just gives an error, so it is not clear what you want to multiply.
Try this:
>> C = bsxfun(@times,A,permute(B,[1,3,2]));
>> D = reshape(C,size(C,1),[]);
>> size(D)
ans =
101078 192

请先登录,再进行评论。

更多回答(1 个)

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by