# 字符串匹配+分类（文本）

``````
ffid = fopen('diagnosis.txt','r');
tline = fgetl(ffid);
i = 1;
while feof(ffid) == 0
tline1{i,1} = fgetl(ffid);
i = i+1;
end
Yes = cell(2185,2);
%% 如果匹配到CIN1-2或者CIN-1-2，CIN2-3或者CIN-2-3，直接剔除
aTI = 0;
%% 如果匹配到CIN1或者CIN-1,扔到CIN1
aCIN1 = 0;
%% 如果匹配到CIN2或者CIN-2,扔到CIN2
aCIN2 = 0;
%% 如果匹配到CIN3或者CIN-3,扔到CIN3
aCIN3 = 0;
%% 如果带癌字，就分到癌
aCancer = 0;
%% 如果带Normal，就分到Normal
aNormal = 0;
%% 其余的分到正常
aYes = 0;
for i = 1 : 6975
if ~isempty(strfind(tline1{i},'CIN1-2'))||~isempty(strfind(tline1{i},'CIN-1-2'))||~isempty(strfind(tline1{i},'CIN2-3'))||~isempty(strfind(tline1{i},'CIN-2-3'))
%如果字符串中含有“CIN1”则执行if内的程序
aTI = aTI + 1;
TI(aTI) = i;
elseif ~isempty(strfind(tline1{i},'CIN1'))||~isempty(strfind(tline1{i},'CIN-1'))
aCIN1 = aCIN1 +1;
CIN1(aCIN1) = i;
elseif ~isempty(strfind(tline1{i},'CIN2'))||~isempty(strfind(tline1{i},'CIN-2'))
aCIN2 = aCIN2 +1;
CIN2(aCIN2) = i;
elseif ~isempty(strfind(tline1{i},'CIN3'))||~isempty(strfind(tline1{i},'CIN-3'))
aCIN3 = aCIN3 +1;
CIN3(aCIN3) = i;
elseif ~isempty(strfind(tline1{i},'NORMAL'))||~isempty(strfind(tline1{i},'NORMAL'))
aNormal = aNormal +1;
Normal(aNormal) = i;
elseif ~isempty(strfind(tline1{i},'癌'))||~isempty(strfind(tline1{i},'癌'))
aCancer = aCancer +1;
Cancer(aCancer) = i;
else
aYes = aYes + 1;
Yes{aYes,1} =  i;
Yes{aYes,2} =  tline1{i};
end
end
``````