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

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.

 Accepted Answer

Note - NaN values are not included in the grouping
load('SNR_GPS.mat')
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

8 Comments

Thanks, but what I would like is to rearrange the whole row of data into new groups. For example in picture SNR_GPS_Mean the 4th row is 16.2891, so copy the whole 4throw in SNR_GPS to first group. And the 8th row of SNR_GPS_Mean is 27.5701, so so copy the whole 8th row in SNR_GPS to second group something like that.
The code for SNR_GPS_Mean is here:
SNR_GPS_Mean = mean(SNR_GPS,2);
Okay, the partition is to be done based on mean values -
load('SNR_GPS.mat')
data = mean(SNR_GPS, 2);
%removing NaN data
data = rmmissing(data)
data = 11×1
0.1419 16.2891 27.5701 33.5483 1.2693 34.6277 39.4309 38.3797 0.6048 37.8459
k = discretize(data, [-Inf 25 36 Inf]);
out = accumarray(k, data, [], @(x) {x.'})
out = 3×1 cell array
{[ 0.1419 16.2891 1.2693 0.6048]} {[ 27.5701 33.5483 34.6277]} {[39.4309 38.3797 37.8459 38.7296]}
Sorry to bother you but one more question, I tried to use your method of using accumarray to rearrange data into 3 groups. So I generated a new variable SNR_GPS_SD_2 having the same size as the SNR_GPS_Mean_2. I checked that the accumulating elements of SNR_GPS_Mean_3 is same as the SNR_GPS_SD_2. But when I run the file, it shows the error of using accumarray, stating Second input must be a vector with one element for each row in the first input, or a scalar. What is wrong behind that and how can I solve that? Thanks again for your help.
This is the original code:
SNR_GPS_Mean_4 = accumarray(SNR_GPS_Mean_3, SNR_GPS_Mean_2, [], @(x) {x.'});
This is the new code:
SNR_GPS_SD_3 = accumarray(SNR_GPS_Mean_3, SNR_GPS_SD_2, [], @(x) {x.'});
Did you remove the NaN values (for the new data) as I did, using rmmissing ?
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!
No problem, I'm always happy to help :) You're welcome!

Sign in to comment.

More Answers (0)

Products

Release

R2023b

Tags

Community Treasure Hunt

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

Start Hunting!