How to delete select rows of data that are non-uniform?
Show older comments
I have a 4096x32 data set and I need to delete rows of data. For example Keep rows 1-32 Delete rows 33-83 Keep rows 84-116. I have a code do to this but this issue is that the number of I need deleted goes in the pattern 50-50-51. Anybody know how to do this?
Answers (2)
Build a vector of indices of all rows that you want to delete, and use it for performing a one-shot deletion. Don't iterate a deletions one row or block of rows at a time, as the size of your matrix would decreases each time rows are deleted, which generally invalidates pre-computed indices. Example:
>> A = rand(5, 3)
A =
0.1233 0.9027 0.9001
0.1839 0.9448 0.3692
0.2400 0.4909 0.1112
0.4173 0.4893 0.7803
0.0497 0.3377 0.3897
>> rIds = [2, 2, 2, 2, 5] ; % Vector of ids of ALL rows to delete.
>> A(rIds,:) = []
A =
0.1233 0.9027 0.9001
0.2400 0.4909 0.1112
0.4173 0.4893 0.7803
As you can see, this erased row 2 once only. A loop like
for k = 1:numel(rowIds), A(rowIds(k),:) = [] ; end
would fail for the reason that I mentioned.
Image Analyst
on 15 Mar 2013
You say " I have a code do to this". Do you have code to do this or not? What is "this"? You simply say:
data(row1:row2, :) = [];
for whatever row1 and row2 you want. I'm not sure what code you're missing and what you have.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!