# Separating data to 3 different groups according to specific range of number in a variable

1 view (last 30 days)
Yat Chi on 22 Feb 2024
Commented: Dyuman Joshi on 22 Feb 2024
Hello, I have a 32x1875 sized variable named SNR_GPS, each rows represent the number of signals to noise ratio (SNR) of each satellite in the 1875 seconds. The first thing I would like is to calculate the mean SNR of each satellite which I successfully done do. But when I would like to arrange the satellites into 3 separate variables according to the requirements ( First group: SNR < 25, Second group: SNR 25-35, Third group: SNR>35 ), my old code failed to compile that. Is there any method to complete that? Thanks for your help.

Dyuman Joshi on 22 Feb 2024
Note - NaN values are not included in the grouping
data = SNR_GPS(~isnan(SNR_GPS))
data = 20625x1
0 22 23 39 0 31 40 41 0 32
k = discretize(data, [-Inf 25 36 Inf])
k = 20625x1
1 1 1 3 1 2 3 3 1 2
out = accumarray(k, data, [], @(x) {x})
out = 3x1 cell array
{7037x1 double} {5184x1 double} {8404x1 double}
%checking the data
z = out{2}
z = 5184x1
31 32 32 32 32 30 34 30 34 30
min(z)
ans = 25
max(z)
ans = 35
Yat Chi on 22 Feb 2024
Nevermind it worked again. Originally i used the rmmissing but still got the problem, maybe there is conflict in matlab code. Sorry for bothering you long and thanks very much for your help today!
Dyuman Joshi on 22 Feb 2024
No problem, I'm always happy to help :) You're welcome!

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2023b

### Community Treasure Hunt

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

Start Hunting!