From: Mario Eduardo Villanueva on
I have a matrix with different data (around 10k rows) obtained from image analysis, this data is in tab separated value files, i want to add some constraints in order to delete noisy/unused data. In order to achieve this I'm using the find function:

FILESLIST=dir(PATH);
RawData=[];

for i=4:length(FILESLIST);

NAME=FILESLIST(i).name;
FILENAME=strcat(NAME);
FILE=strcat(PATH,FILENAME);
% Read in File
id= fopen(FILE);

% Determine number of rows
rownumber=countRows(id);

%Get Data
DATA=textread(FILE,'',-1,'delimiter','\t', ...
'headerlines',1,'emptyvalue',NaN);

[RowToDelete,Column]=find((DATA(:,2))<(20.0)); %criterion: area diameter less than 8
DATA(RowToDelete,:)=[];

[RowToDelete2,Column2]=find((DATA(:,4))<(0.80)); %criterion: circularity less than 0.8
DATA(RowToDelete2,:)=[];


RawData=vertcat(RawData,DATA);

ROWNUMBERTOTAL=ROWNUMBERTOTAL+rownumber;

end;

%%%%% CONDITION DATA


COMPLETEDATA=RawData;


%%%%%
AREADIAMETER=2*sqrt(COMPLETEDATA(:,2)/(pi));
IQRAREA=iqr(AREADIAMETER);
hAREA=2*IQRAREA*(length(AREADIAMETER))^(-1/3);
NBINAREA=ceil((max(AREADIAMETER)-min(AREADIAMETER))/hAREA);

figure(1);
bar(hist(AREADIAMETER,NBINAREA)./sum(hist(AREADIAMETER,NBINAREA)),1);
title('Area derived Diameter distribution');

%%%

At this point my normalized histogram shows correctly (x axe from 8 to 40) but if I add a third constraint:

% [RowToDelete2,Column3]=find((DATA(:,2))>(500)); %criterion: area diameter greater than 40
% DATA(RowToDelete2,:)=[];

then my normalized histogram shows some values from 0 to 160 in the x axis, if i plot:

hist(AREADIAMETER,NBINAREA)

then it shows correctly.

Many Thanks,

by the way Im new to MATLAB so if you have some comments to improve my code are more than welcome.