How to delete or ignore the rows with duplicate values in time

3 views (last 30 days)
I have a 26400x2 table with time and numbers representing satellite IDs for every second (as in the picture, the file is too large to upload). I need to get the number of satellites in time (which I want to plot later). This should simply be the height of each vector containing 1 second. However, there are some duplicate sat IDs in each second, and I don't know how to remove them. I tried the following:
t1 = raw.UTCTime(1);
t2 = raw.UTCTime(end);
t = (t1:seconds(1):t2)';
num_sats_gps = zeros(length(t),1);
for i = 1:length(t)
idx = gps.UTCTime == t(i);
uniq = unique(gps.Svid(idx));
num_sats_gps(i,1) = height(uniq);
end
but it doesn't work like it's supposed to, the result gives me vector with 0 values. Is there any other approach to this? Any answer would be highly appreciated!

Accepted Answer

Yash
Yash on 21 Jun 2023
There might be an issue with how you're indexing the table or filtering duplicates, other than that, your code seems right to me.
As an alternative, you can use the 'splitapply' function. Take the help of the below mentioned code.
% Assuming your table is named 'raw' with columns 'UTCTime' and 'Svid'
t1 = raw.UTCTime(1);
t2 = raw.UTCTime(end);
t = (t1:seconds(1):t2)';
%Storing the resulting count in num_sats_gps
num_sats_gps = splitapply(@(x) numel(unique(x)), raw.Svid, discretize(raw.UTCTime, t));
%Using 'discretize' function to divide the time range into one-second intervals
The splitapply function applies the anonymous function @(x) numel(unique(x)) to each group of satellite IDs (x) associated with a specific time interval. It counts the number of unique satellite IDs in each group.
Hope this helps.
  1 Comment
Simona Blaskova
Simona Blaskova on 23 Jun 2023
Thank you so much, your solution works perfectly! I think the problem was with time, which needed to be discretized.

Sign in to comment.

More Answers (0)

Categories

Find more on CubeSat and Satellites in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!