Multiplying each number in a matrix by a row

I have a matrix A and i want each value in a row to the order of a row B. Then, the sum of all these values entered back into the same place as the number in A.
eg
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15]
B = [1; 2; 3; 4; 5; 6]
therefore sum(A(1,1).^B) back into A(1,1).
Any idea how i can do this?
Please help. Thanks

Answers (1)

hi, you can try :
% Your data
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15];
B = [1; 2; 3; 4; 5; 6];
% Cell
C=cell(size(A));
for x=1:3
for y=1:5
C{x,y}=kron(A(x,y),B);
end
end
% Summation :
G=cell(size(C));
for x=1:3
for y=1:5
G{x,y}=sum(C{x,y});
end
end
G=cell2mat(G);

2 Comments

thanks but im affraid this produces the error;
Conversion to cell from double is not possible.
Error in Untitled5 (line 9) C(x,y)=kron(A(x,y),B);
i corrected that error its simple change from () to {} because its a cell
The code works fine

This question is closed.

Asked:

on 8 Apr 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!