Multiplying each number in a matrix by a row
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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)
Youssef Khmou
on 8 Apr 2013
Edited: Youssef Khmou
on 8 Apr 2013
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
Jessica Parry
on 8 Apr 2013
Youssef Khmou
on 8 Apr 2013
i corrected that error its simple change from () to {} because its a cell
The code works fine
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!