Multiplying two vectors to form a matrix
이전 댓글 표시
Hello, I have two vectors x and y, both 601x1. I want to multiply them to form a matrix of 601x601, but the values inside the matrix have to be sqrt(x^2+y^2). How do I do this? Thanks.
채택된 답변
추가 답변 (2개)
x = rand(601,1) ;
y = rand(601,1) ;
iwant = sqrt(x.^2+y'.^2) ;
size(iwant)
Walter Roberson
2022년 2월 25일
D = sqrt(x.'.^2 + y.^2)
댓글 수: 4
Walter Roberson
2022년 2월 25일
Nikola Segedin
2022년 2월 25일
Jan
2022년 2월 25일
@Nikola Segedin: Which Matlab versionare you using? Since R2016b an "implicit expanding" is applied. For former versions:
D = sqrt(bsxfun(@plus, x.'.^2, y.^2))
Nikola Segedin
2022년 2월 25일
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!