matlab - 在MATLAB中保存多个txt文件时如何保存带有连续数字的文件名?
问题描述
我有大约 2000 条大小为 7611 * 1 的数据。我想将每个数据保存为 txt 文件。我想把txt文件名保存成1.txt、2.txt、3.txt……格式,怎么办?
另外,我在保存数据的时候,想保持7611*1的格式,怎么办?在这部分中,我将附上我编写的无法正常工作的代码..请帮助。谢谢你。
st = data which size is 7611*1
for i = 1:2000
data = fopen('%d.txt','w',i); % The next code doesn't work. I wrote this code
% to tell you what form I want.
fprintf(data,'%d \n',st); % I want to save as a column vector, but when I
% run it with the code next to it, the broken
% txt file is saved... I cant find reason..
end
解决方案
我建议sprintf
在你的 for 循环中使用命令来创建文件名,即
for i = 1:2000
fName = sprintf('%0.0f.txt',i) % create file name
data = fopen(fName,'w', ... ); % include additional specifications as needed
fprintf( ... ) % include specifications as needed
end
推荐阅读
- angularjs - 如何在角度电话猫中运行量角器测试?
- ruby - Ruby - 无法使用数组整数执行计算
- java - 如何在 Android 中水平滚动 ImageView?
- json - MariaDB JSON_SEARCH 函数不适用于变量
- django-rest-framework - 令牌认证后Django Rest Framework注销不起作用
- javascript - 如何在 html 表中动态创建带有 div 类的输入元素?
- nginx - Kubernetes集群中的Nginx微服务网关配置
- php - 如何以 JSON 格式编码 mysql 数据?
- apache - apache mod_rewrite 让我们加密不重定向
- python - Kivy:使用滑块更新 matplotlib 画布