Apply a formula and create a new matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
matlabuser
le 27 Août 2020
Commenté : matlabuser
le 28 Août 2020
Suppose I have 2 matrices :
x = ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352661/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352661/image.png)
and y = ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352664/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352664/image.png)
I am not able to figure out the code that will output a matrix which calculates the following: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352667/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352667/image.png)
1 commentaire
Réponse acceptée
Bruno Luong
le 27 Août 2020
Modifié(e) : Bruno Luong
le 27 Août 2020
b.'*sum(A,2)
sum(A,2).'*b % preferable than
sum(A.'*b) % or
sum(b.'*A) % or
sum(A.*b,'all')
or
s = 0;
for i=1:size(A,1)
for j=1:size(A,2)
s=s+A(i,j)*b(i);
end
end
s
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!