How to delete or ignore the rows with duplicate values in time
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Yash
2023-6-21
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 CubeSat and Satellites 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!