使用特定数字在 matlab 中创建一个巨大的文本文件?
create a huge text file in matlab with specific numbers?
我如何在 matlab 中创建一个包含数百万行的巨大文本文件,其中包含数字 9876543210 和 5 个空格,并再次重复数百万行的数字和 5 个空格?
myNumbers= (0:9);
fid = fopen('lastFile.txt','wt');
for i=1:99
fprintf(fid,'%d%d%d%d%d%d%d%d%d%d \r',myNumbers);
end
fclose(fid);
循环方式:
myNumbers= (0:9);
repeats = 20; %// number of times to repeat array on each line
lines = 99; %// number of lines to write to file
fid = fopen('lastFile.txt','wt');
for n=1:lines
for r=1:repeats
fprintf(fid,'%d%d%d%d%d%d%d%d%d%d ',myNumbers); %// no return just yet
end
fprintf(fid, '\n'); %// or \r if that's what you really want
end
fclose(fid);
我将 \r
更改为 \n
因为它对我来说更有意义。除非你用的是 Mac OS 9. 我也把格式规范末尾的 space 改成了 5 spaces,因为这就是你说的你想要的.
要让数组在一行上重复,您只需确保在该行上包含您想要的所有内容之前不要添加换行符。然后对任意多行执行此操作。
还有其他方法可以做到这一点,但这是最直接的。
我如何在 matlab 中创建一个包含数百万行的巨大文本文件,其中包含数字 9876543210 和 5 个空格,并再次重复数百万行的数字和 5 个空格?
myNumbers= (0:9);
fid = fopen('lastFile.txt','wt');
for i=1:99
fprintf(fid,'%d%d%d%d%d%d%d%d%d%d \r',myNumbers);
end
fclose(fid);
循环方式:
myNumbers= (0:9);
repeats = 20; %// number of times to repeat array on each line
lines = 99; %// number of lines to write to file
fid = fopen('lastFile.txt','wt');
for n=1:lines
for r=1:repeats
fprintf(fid,'%d%d%d%d%d%d%d%d%d%d ',myNumbers); %// no return just yet
end
fprintf(fid, '\n'); %// or \r if that's what you really want
end
fclose(fid);
我将 \r
更改为 \n
因为它对我来说更有意义。除非你用的是 Mac OS 9. 我也把格式规范末尾的 space 改成了 5 spaces,因为这就是你说的你想要的.
要让数组在一行上重复,您只需确保在该行上包含您想要的所有内容之前不要添加换行符。然后对任意多行执行此操作。
还有其他方法可以做到这一点,但这是最直接的。