Help extracting rows based on unique column 1 data
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Brantosaurus
am 19 Nov. 2022
Beantwortet: Campion Loong
am 30 Nov. 2022
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 Kommentare
Image Analyst
am 19 Nov. 2022
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.
Akzeptierte Antwort
Star Strider
am 19 Nov. 2022
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 Kommentare
Weitere Antworten (1)
Campion Loong
am 30 Nov. 2022
% 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 Kommentare
Siehe auch
Kategorien
Mehr zu Data Preprocessing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!