2

我想根据保存在“x.txt”中的索引在文本文件“marine_forservers.txt”中搜索字符串,然后将这些字符串保存在输出文件中这是我尝试过的代码,但它不能将字符串保存到文件中可以有人帮我吗??

search = importdata('marine_forservers.txt');
patterns=importdata('x.txt');
fid = fopen('outputI.txt','w');
for i=1:length(patterns)
    for j = 1:16709
        if(j==patterns(i))
         str= search(j);
         fprintf(fid, '%s\n', str);
   end
end
end
fclose(fid);

我在 ==> suppI 中在 8 fprintf(fid, '%s\n', str);

4

1 回答 1

1

这个错误:

??? Error using ==> fprintf Function is not defined for 'cell' inputs. 

告诉你你需要知道的一切;str 不是字符数组 - 它是一个 MATLAB 单元:

http://www.mathworks.com/help/matlab/ref/cell.html

这应该解决它:

fprintf(fid, '%s\n', str{1});

作为旁注,这就是为什么您应该始终在原始问题中包含错误消息文本...

于 2013-01-09T13:54:40.287 回答