查看单个帖子
旧 2019-12-10, 16:49   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在MATLAB中使用循环变量创建字符串?

我有这样一个循环:

for i=1:no %some calculations fid = fopen('c:\\out.txt','wt'); %write something to the file fclose(fid); end 我希望将数据写入这样的不同文件中:
  • 对于i=1 ,数据被写入out1.txt
  • 对于i=2 ,数据被写入out2.txt
  • 对于i=3 ,数据被写入out3.txt
  • 等等
做'out'+ i行不通。 如何才能做到这一点?


回答:
另一个选择是函数SPRINTF

fid = fopen(sprintf('c:\\out%d.txt',i),'wt');

更多&回答...
poster 当前离线   回复时引用此帖