필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Simona Blaskova
Simona Blaskova 2023년 6월 21일
댓글: Simona Blaskova 2023년 6월 23일
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!

채택된 답변

Yash
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.
  댓글 수: 1
Simona Blaskova
Simona Blaskova 2023년 6월 23일
Thank you so much, your solution works perfectly! I think the problem was with time, which needed to be discretized.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 CubeSat and Satellites에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by