How to delete or ignore the rows with duplicate values in time
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Simona Blaskova
il 21 Giu 2023
Commentato: Simona Blaskova
il 23 Giu 2023
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!

0 Commenti
Risposta accettata
Yash
il 21 Giu 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Reference Applications in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!