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).
更多回答(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!