필터 지우기
필터 지우기

Magnitude of a matrix

조회 수: 47 (최근 30일)
David Harra
David Harra 2021년 9월 16일
댓글: Star Strider 2021년 9월 16일
I have a 1000 x 3 matrix where each column is associated the the x,y and z-direction. For each row I want to find the magnitude such that I have a 1000 x 1 array returned.
x=randi(100,1000,3);
X=norm(x(1:1000,1:3))
I tried this but I am only only getting a single number rather than a 1000 x 3 array.
Thanks
Dave :)

채택된 답변

Star Strider
Star Strider 2021년 9월 16일
See if the vecnorm funcion (introduced in R2017b) will do what you want —
x=randi(100,1000,3);
X=vecnorm(x,2,2)
X = 1000×1
89.5600 69.0290 104.2785 84.2734 42.9185 76.2693 105.6504 96.7316 64.1950 113.6002
.
  댓글 수: 2
David Harra
David Harra 2021년 9월 16일
Thanks.
Could I just ask you about this line
X=vecnorm(x,2,2)
I can see this takes my matrix x as the first argument, but what does the 2,2 inside the bracket do?
Dave :)
Star Strider
Star Strider 2021년 9월 16일
My pleasure!
The first 2 specifies the 2-norm (rather than others), and the second 2 specifies that the function is to take the norm across the rows (dimension 2) rather than down the columns (dimension 1, the default dimension) or other dimensions if the matrix had more than 2.
Specifying only the matrix would take the 2-norm of the columns.
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by