Multiplying each number in a matrix by a row
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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
am 8 Apr. 2013
Bearbeitet: Youssef Khmou
am 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 Kommentare
Jessica Parry
am 8 Apr. 2013
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.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!