# use array operations to add 360 to elements of an array less than -180 without a loop

조회 수: 2(최근 30일)
Stephen Marsden 2023년 2월 2일
답변: the cyclist 2023년 2월 2일
I have an array of angles that are all close to zero. When plotted the y-axis has limits of -380 , +20. The 360 degree jump when the value crosses zero is dominant over other trends. Mean and standard deviation are meaningless. I would like to add 360 if the value is less than -180 and subtract 360 if the value is more than 180. I could do a do loop with an if statement, but I'm hoping to do it as an array operation.
A = [1,2,3,359,5,358,355];
if A>=180
A2=A-360;
end
A2
A2 =
1 2 3 -1 5 -2 -5

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

### 채택된 답변

the cyclist 2023년 2월 2일
A = [1,2,3,359,5,358,355];
idx = (A>=180);
A(idx) = A(idx) - 360
A = 1×7
1 2 3 -1 5 -2 -5

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

### 범주

Find more on Matrices and Arrays in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by