Re-scaling matrix entries to lie within a range

Hey all,
Basically, I have a matrix containing a wide range of phase angles, but I want to re-scale all these angles to their equivalent values within the range [-pi, pi]. Hence, for example, 1.5*pi will become -0.5*pi.
Would anyone have any tips on how to do this? I'm not looking for a full answer; merely any suggestions that would help me get started would be much appreciated!
Craig

 채택된 답변

Sven
Sven 2011년 11월 21일

0 개 추천

You can use the "mod" command with modulus 2*pi, then minus pi from the result. For example:
mod(4.5*pi + pi, 2*pi) - pi
ans =
-1.5708
mod(1.5*pi + pi, 2*pi) - pi
ans =
1.5708
(above edited for Walter's amendment)

댓글 수: 3

>> mod(0,2*pi)-pi
ans =
-3.14159265358979
I don't think so...
Sven
Sven 2011년 11월 22일
Oops. Yep, you're right of course Walter.. what can I say... I was in a rush? Edited accordingly :)
You need to update your "ans" as well ;-)

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2011년 11월 22일

2 개 추천

mod(angle + pi, 2*pi) - pi
Note: this will produce the range semi-open interval [-pi, pi) . The original closed interval [-pi, pi] is ambiguous as to what -pi or pi exactly should map to (as they are the same angle)
C Meek
C Meek 2011년 11월 22일

0 개 추천

Thanks, that's is helping me on my way.
However, surely once 1.5*pi has been re-scaled it should be -1.5708, and not +1.5708, or am I missing something?

댓글 수: 1

Sven
Sven 2011년 11월 22일
Yeah, you're right... original answer was "on the way", but not quite correct. It's updated now in a way that gives correct output.

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2011년 11월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by