%%读入数据
[schoolID,schoolName] = xlsread('Problem C - IPEDS UID for Potential Candidate Schools.xls','A2:B2978');
lengthOfOrigin = length(schoolID);
%%匹配ID
% A~E
for alphabet = 0:4
selectedSchoolID = xlsread('ID.xls',[char('A' + alphabet) '1:' char('A' + alphabet) '2389' ]);%
lengthOfselected = length(selectedSchoolID);
index_SelectedSchoolName = 1;
for index_SelectedID = 1 : lengthOfselected
index_Origin = find(schoolID == selectedSchoolID(index_SelectedID));
selectedSchoolName{index_SelectedSchoolName} = char(schoolName(index_Origin));
%xlswrite('schoolName',selectedSchoolName(index_SelectedSchoolName),'sheet1',[char('A' + alphabet) num2str(index_SelectedSchoolName)]);
index_SelectedSchoolName = index_SelectedSchoolName + 1;
end
xlswrite('selectedSchoolIDAndName',selectedSchoolID,['sheet' num2str(alphabet+1)],[char('A') num2str(1) ':' char('A') num2str(2389)]);
xlswrite('selectedSchoolIDAndName',selectedSchoolName',['sheet' num2str(alphabet+1)],[char('B') num2str(1) ':' char('B') num2str(2389)]);
end
其中selectedSchoolName即一个cell数组。
注意:
1.向cell赋值的方式
selectedSchoolName{1} = 'xxx';
<pre name="code" class="plain">selectedSchoolName{2} = 'yyy';
2.将一个cell转换为字符串的方式:
char(schoolName(index_Origin));
3.将一个cell中的字符串一次性写入Excel中方式
<pre name="code" class="plain">xlswrite('selectedSchoolIDAndName',selectedSchoolName',['sheet' num2str(alphabet+1)],[char('B') num2str(1) ':' char('B') num2str(2389)]);