Turning a product of two vectors into a matrix without using for loops?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
daniel adams
am 8 Okt. 2021
Beantwortet: Star Strider
am 8 Okt. 2021
I have to two vectors x and y, each of length n. I want a matrix M where the elements of M are
. How can I construct M on matlab without using a for loop?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/761741/image.png)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 8 Okt. 2021
I believe something like this should do what you want —
x = 1:10
y = 11:20
M = x(:)*y
Using ‘x’ as x(:) forces it to become a column vector. The rest is straightforward vector-matrix multiplication.
.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!