Subtraction of set value from specific elements in column once criteria met

4 views (last 30 days)
Hi everyone,
I'm using this device that outputs counts in a set column. The problem is when the count goes negative the output goes to the max positive number (65535) and starts counting down. So the column could out put values such as (1790, 30,1500, 65530....).
I'm hoping to subtract 65535 from these "negative" values to get the true negative value (1790,30,1500, -5). The positive count will never go above 5000 so I was trying to subtract 65535 from every element above a set limit but not having any luck. I haven't been able to set it up so that any value above some set limit is subtract by 65535. I've just ended up setting all values to that set value.
I'd appreaciate any assistance.
Thanks in advance

Accepted Answer

the cyclist
the cyclist on 30 May 2021
threshold = 5000; % Set this to the limit value you want
x(x>threshold) = x(x>threshold) - 65535;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!