How can I find and substract only these values from a dataset which are bigger than a threshold?

Hey people. I am quite new with matlab. I have a big dataset consisting of three columns (x,y,z). I would like to find x-values which are bigger than a threshold. these values i would like to substract by 360. I was thinking of a if condition sth like:
if x > 180
xnew = x - 360;
else
xnew = x;
end
This is obviously wrong. Does somebody have a advice? Thanks a lot in advance! Cheers P

 Accepted Answer

xnew = mod(x+180,360)-180

1 Comment

Be careful that this solution does not do exactly what you asked for. But I think it probably does what you actually wanted.
x = -360:720;
xnew_1 = x;
xnew_1(xnew_1>180) = xnew_1(xnew_1>180) - 360;
xnew_2 = mod(x+180,360)-180;
figure
plot(x,xnew_1,x,xnew_2)
axis tight
legend({'cyclist','stephen'},'Location','SouthEast')

Sign in to comment.

More Answers (1)

xnew = x;
xnew(xnew>180) = xnew - 360;

2 Comments

Thanks a lot for your answer. I tried your solution already but receive the following error: 'In an assignment A(I) = B, the number of elements in B and I must be the same.'
Oops, should have been
xnew = x;
xnew(xnew>180) = xnew(xnew>180) - 360;

Sign in to comment.

Categories

Asked:

PK
on 5 Feb 2016

Commented:

on 5 Feb 2016

Community Treasure Hunt

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

Start Hunting!