Substracting a number from certain section of the array

I have a number series 8654 elements having data in format (degree) as follows (just an example):
A = [ 1.002 2.003 3.004 4.005 339.006 341.007 342.008 343.009 1.002 2.003 3.004 4.005];
I am currently using the following code to make elements in the above array having values more than 300 substracted by 360;
if (A(:,1) > 300)
A(:,2)= 360-A(:,1);
else
A(:,2) = A(:,1);
end
to make a new array in second coloumn which looks like
A = [ 1.002 2.003 3.004 4.005 21 19 18 17 1.002 2.003 3.004 4.005];
But I am getting the same array as A = [ 1.002 2.003 3.004 4.005 339.006 341.007 342.008 343.009 1.002 2.003 3.004 4.005];
I dont know which place I am going wrong !! Guidance required !!

 Accepted Answer

VBBV
VBBV on 18 Nov 2020
Edited: VBBV on 18 Nov 2020
Try this
A = [ 1.002 2.003 3.004 4.005 339.006 341.007 342.008 343.009 1.002 2.003 3.004 4.005];% your array
A(A>300) = 360-A(A>300) % you want

More Answers (0)

Products

Release

R2020a

Asked:

on 18 Nov 2020

Commented:

on 18 Nov 2020

Community Treasure Hunt

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

Start Hunting!