Delete m consecutive rows every n rows
2 次查看(过去 30 天)
显示 更早的评论
Hello! I'm looking to find a way to delete certain rows in a big table that i'm working with. I would like to find a smart way to delete m consecutive rows every n rows. In my case I have m=6 and n=24--> i want rows 25:30 to be erased while rows 31:54 preserved, up till the end. Hope that the question is clear. Thank you!
采纳的回答
Voss
2022-1-25
编辑:Voss
2022-1-25
Here's one way to do it, with a matrix. The logic would be the same for a table.
m = 6;
n = 24;
N = 87;
data = (1:N).'+(0:10:20); % some data
disp(data);
idx = (n+1:n+m).'+(n+m)*(0:ceil(N/(n+m))-1); % index of rows to delete
disp(idx);
idx(idx > N) = []; % don't go off the end
disp(idx);
data(idx,:) = []; % delete the dang rows
disp(data);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!