Matalab 中如何用一个cell存储多个字符串并将其一次性写入EXcel中

%%读入数据
[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';
selectedSchoolName{2} = 'yyy';

 
  
2.将一个cell转换为字符串的方式:
char(schoolName(index_Origin));

3.将一个cell中的字符串一次性写入Excel中方式
xlswrite('selectedSchoolIDAndName',selectedSchoolName',['sheet' num2str(alphabet+1)],[char('B')  num2str(1) ':' char('B') num2str(2389)]);

 
  

你可能感兴趣的:(Matalab)