Turning a product of two vectors into a matrix without using for loops?

조회 수: 1 (최근 30일)
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?

채택된 답변

Star Strider
Star Strider 2021년 10월 8일
I believe something like this should do what you want —
x = 1:10
x = 1×10
1 2 3 4 5 6 7 8 9 10
y = 11:20
y = 1×10
11 12 13 14 15 16 17 18 19 20
M = x(:)*y
M = 10×10
11 12 13 14 15 16 17 18 19 20 22 24 26 28 30 32 34 36 38 40 33 36 39 42 45 48 51 54 57 60 44 48 52 56 60 64 68 72 76 80 55 60 65 70 75 80 85 90 95 100 66 72 78 84 90 96 102 108 114 120 77 84 91 98 105 112 119 126 133 140 88 96 104 112 120 128 136 144 152 160 99 108 117 126 135 144 153 162 171 180 110 120 130 140 150 160 170 180 190 200
Using ‘x’ as x(:) forces it to become a column vector. The rest is straightforward vector-matrix multiplication.
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by