# MATLAB code partially completes task - no error.

1 view (last 30 days)
Nolan Miller on 27 Jun 2019
Commented: Nolan Miller on 28 Jun 2019
Hello all,
I have a table that consists of about 30,000 to 40,000 rows of data (depending on input file), once the table is produced, I have a segment of code that combs through three specific columns marking each position where the value is less than 2. The second segment then goes through this newly created matrix, removing any duplicates, and then removes the rows with any value less than 2 in the three columns from the original table. Each time I run these two segments, the size of my table will decrease by about 2 or 3, but then the code stops running without showing any error message. I don't know if there is a problem with my code or if I am processing too much at once. Thank you for your assistance! (MATLAB Version: 9.3.0.713579 (R2017b))
%First Segment
vox_min = 2; %threshold value
removesmall = []; %Initial array for collecting positions of values less than vox_min
for k = 1:size(pore_char.BoundingBox, 1)
for j = [4, 5, 6]
if pore_char.BoundingBox(k,j) < vox_min
removesmall = [removesmall, k]; %collects all positions less than vox_min
end
end
end
%Second Segment
removesmall_unique = unique(removesmall); %removes duplicate rows to ensure correct rows are deleted
for i = 1:size(removesmall_unique)
pore_char(removesmall_unique(i), :) = []; %removes rows with values less than vox_min
end
Joel Bay on 27 Jun 2019
Edited: Joel Bay on 27 Jun 2019
Hi,
First tip, you can use length() instead of size(), length() returns the number of elements in the largest dimension.
To be clear, your code hopes to simply remove only 1 of duplicate small values in the 4th 5th and 6th collumns? So if you had 3 duplicate small values you would keep two of them?
You may want to look at logical indexing. Here's code that would remove all small values.
pore_char.BoundingBox = pore_char.BoundingBox((pore_char.BoundingBox(:,4) > vox_min), :)
pore_char.BoundingBox = pore_char.BoundingBox((pore_char.BoundingBox(:,5) > vox_min), :)
pore_char.BoundingBox = pore_char.BoundingBox((pore_char.BoundingBox(:,6) > vox_min), :)
Heres code that stores all small values in a new array and then removes them from original array:
pore_char.BoundingBoxSmall = pore_char.BoundingBox((pore_char.BoundingBox(:,4) < vox_min), :)
pore_char.BoundingBoxSmall = [pore_char.BoundingBoxSmall pore_char.BoundingBox((pore_char.BoundingBox(:,5) < vox_min), :)]
pore_char.BoundingBoxSmall = [pore_char.BoundingBoxSmall pore_char.BoundingBox((pore_char.BoundingBox(:,6) < vox_min), :)]
pore_char.BoundingBox = pore_char.BoundingBox((pore_char.BoundingBox(:,4) > vox_min), :)
pore_char.BoundingBox = pore_char.BoundingBox((pore_char.BoundingBox(:,5) > vox_min), :)
pore_char.BoundingBox = pore_char.BoundingBox((pore_char.BoundingBox(:,6) > vox_min), :)
Or a more simple example:
A = 10.*rand(100,3); %creates a 100x3 matrix of random numbers between 0 and 10
A = A((A(:,1)>4),:); %redefines A as every row that meets the criteria of the first collumn in that row being > 4.
Nolan Miller on 28 Jun 2019
The last example worked! I needed the script to rake through all three of the columns removing any row where any of the three values was less than a value. I planned on using a for loop to repeat the simple example for each column, but the index always went out of range due to the deleted rows.
It's working now with just pasting the same step each time - I'm sure there is a more elegant way to do this, but it works! Thank you very much!

Joel Bay on 27 Jun 2019
If my comment helps you enough could you accept this answer?