Help extracting rows based on unique column 1 data
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a large MxN matrix of data from which i would like to extract specific rows of data.
The first column of the matrix contains a chronological timebase in seconds, in ascending order.
t1 a1 b1 .. n1
t2 a2 b2 .. n2
:
talpha ..
:
tbeta ..
:
tgamma ..
:
tm am bm .. nm
I know the unique times of 3 events (talpha, tbeta, tgamma) that occur in column 1.
How do i extract the rows in chronological order based on the knowledge of their unique times?
Tried categorical with valueset and ordinal but no luck!
댓글 수: 2
Image Analyst
2022년 11월 19일
How large is large? How many GB or rows? If it really is large, like hundreds of millions of rows or several GB of data then you may need to use memmapfile. If you just have a few million rows or less, that's not large.
채택된 답변
Star Strider
2022년 11월 19일
There is a lot I don’t unerstand about this problem.
However, if you want to find the unique occurrences of each of the ‘talpha’ , ‘tbeta’ and ‘tgamma’ so that they return the indices of the first incidence of each value, use the unique function with the first two outputs (the unique values, and the indices of the first instance of each value) with the 'stable' argument (to prvent sorting the result).
댓글 수: 2
추가 답변 (1개)
Campion Loong
2022년 11월 30일
% Make some pretend data for your a#/b#/c# numbers
A = rand(10000,1); B = rand(10000,1); C = rand(10000,1);
% Use timetable. Here I assume regular timesteps. If not, use the
% 'RowTimes' N/V pair instead
tt = timetable(A, B, C, 'TimeStep', seconds(1))
If you know the exact time of your unique events
t_alpha = seconds(10);
t_beta = minutes(150);
t_gamma = hours(2);
% Index directly with time. Get all the rows in one go like below, or
% separately as your preferred:
tt([t_alpha; t_beta; t_gamma], :)
Now, if you are not sure the 'exact' time (e.g. your data has some noise)
tt.Time = tt.Time + milliseconds(randn(10000,1)); % mix in some made-up noise
% Exact time index will turn up nothing ...
tt([t_alpha; t_beta; t_gamma], :)
% Use withtol to index with time tolerance:
wt = withtol([t_alpha; t_beta; t_gamma],seconds(0.5))
tt(wt, :)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!