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

Antworten (1)

Youssef  Khmou
Youssef Khmou am 8 Apr. 2013
Bearbeitet: Youssef Khmou am 8 Apr. 2013

0 Stimmen

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 Kommentare

Jessica Parry
Jessica Parry am 8 Apr. 2013
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);
Youssef  Khmou
Youssef Khmou am 8 Apr. 2013
i corrected that error its simple change from () to {} because its a cell
The code works fine

Diese Frage ist geschlossen.

Gefragt:

am 8 Apr. 2013

Geschlossen:

am 20 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by