- The first row of non-zeros is the first row of the data you'd like to isolate.
- The last row of non-zeros is the last row of data you'd like to isolate.
How to remove rows of zero's occurring prior to rows of desired data?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a 2432132x14 timetable, and the first 390000 rows and last 109000 are filled with zeros. I would like to make a new timetable that removes the 390000 rows and 109000 rows and was planning on approaching this by writing a script that simply removes all rows of data full of zero’s. However, there are some rows of 0’s that occur within the data that I want to keep in the new timetable. How can I define in the code that I only want to remove rows of 0’s before and after the desired data appears? For context, this is biological signal data (EEG and others) collected during surgery. The long period of inactivity at the beginning is because the devices have not been turned on yet, and any periods of inactivity that occur after turning on the devices must be kept for analysis. Currently, I have manually defined the data to be included in the populated table, but would like to develop a more generalizable approach that accounts for variations in file sizes and timings when different case data is loaded.
0 comentarios
Respuestas (1)
Adam Danz
el 30 de En. de 2023
Editada: Adam Danz
el 30 de En. de 2023
This demo makes the following assumptions
TT = array2timetable([zeros(4,5);rand(3,5);zeros(2,5);rand(3,5);zeros(6,5)], ...
'RowTimes',datetime(2000,1,1)+days(0:17))
isAllZeros = all(TT{:,:}==0,2)
% find first row that is not all 0s
a = find(~isAllZeros,1,'first')
% find last row that is not all 0s
b = find(~isAllZeros,1,'last')
% Remove select rows of zeros
TT([1:a,b+1:end],:) = []
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!