multiplication of a 3-D matrix by a 1-D array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
yi yang
am 8 Okt. 2022
Bearbeitet: Stephen23
am 11 Okt. 2022
I have a 3-D matrix A = rand(sz1,sz2,sz3) and a 1-D array B = rand(1,sz3).
Is there a biult-in function to do the muliplication like:
C with dimensions of (sz1,sz2,sz3)
for ii = 1:sz3
C(:,:,ii)=A(:,:,ii)*B(ii);
end
0 Kommentare
Akzeptierte Antwort
Stephen23
am 8 Okt. 2022
You don't need a special kind of multiplication, you just need to match the vector orientation to the array:
C = A .* reshape(B,1,1,[])
2 Kommentare
Stephen23
am 11 Okt. 2022
Bearbeitet: Stephen23
am 11 Okt. 2022
"I checked the matlab documentation for .* and did not find an answer for the question below."
The TIMES documentation states:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1151618/image.png)
"In your answer, the 2 matrices have different dimensions and the element-wise multiplication works, why?"
Clicking the link given in the TIMES documentation takes you to this page:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!