0
如何将字符串文件名包含到fopen函数中?请参阅下面的代码和评论。MATLAB - 如何将字符串作为函数的参数
for i=1:5
filename = strcat('Cali',num2str(i));
%first iteration: filename = Cali1
%instead of result.txt there should be Cali1.txt in the following statement, but i want to achieve this by using the string filename
fid = fopen('results.txt', 'wt');
fprintf(fid, 'write something');
fclose(fid);
end
这是[在文档中明确指出](http://www.mathworks.com/help/matlab/ref/fopen.html#btrnoom-1)。将它作为参数传递给函数。 – excaza
可能还需要添加文件扩展名...'filename = strcat('Cali',num2str(i),'.txt'); ' – RTL
那简单!谢谢 – d4rty