Removing Values That Are Negative and Larger Than a Given Value for Specific Columns and Every Row
3 views (last 30 days)
Show older comments
Hi everyone,
I've run into an issue trying to remove certain values from a series of columns within a dataset, and wanted to inquire about any tips people had.
I have a dataset with hundreds of thousands of rows, and want to remove a series of values from the columns 13:end (the rows are not the same length). The values I want to remove are any values that are negative and any that are over 608667. Ideally, the removal process would run through the length of each row, remove all offending values, shift the remaining values left as to avoid leaving any empty space, then repeat this process for all 608667 rows, and return a new variable with the filtered data.
I've attempted this before with the below code, but still cannot get the logic to run through the length of the 13:end column regime before leaving the loop. Hence, I wanted to see what others thought on the matter and if conditional statements might be more efficient?
At the end of this post I've included an example set of data with the region of interest highlighted in red.
Please let me know what you think and if there are any more streamlined ways to approach this.
Thanks in advance!
G2Data=abs(G2Data);
for i = 1:length(G2Data)
if max(G2Data(i,:)) >= 608667 % Last positive ID value in column 1, manually entered due to a conflict implementing the "find" command here.
temprow = G2Data(i,:); % Defines an instantaneous row for removing offending values.
for j = 13:length(temprow) % Finds length of the target region.
if temprow(j) >= 608667
temprow(j:length(temprow)-1) = temprow(j+1:end);
end
end
G2Data(i,1:length(temprow))=temprow;
for k = 13:length(G2Data(i,:))
jan=length(G2Data(i,:))-k-1;
if jan > length(temprow)
G2Data(i,jan)=[]; % Removes offending values.
end
end
end
end

0 Comments
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!