matlab写入空格 txt进行换行
时间: 2023-03-26 22:01:31 浏览: 74
可以使用 fprintf 函数将数据写入 txt 文件中,并在每行末尾添加换行符 "\n",示例代码如下:
```matlab
data = [1 2 3; 4 5 6; 7 8 9];
filename = 'data.txt';
fid = fopen(filename, 'w');
fprintf(fid, '%d %d %d\n', data');
fclose(fid);
```
这样就可以将 data 数组中的数据写入到 data.txt 文件中,并且每行末尾都添加了换行符。
相关问题
matlab写入txt进行换行
可以使用 fprintf 函数将数据写入 txt 文件,并在需要换行的地方使用 \n 符号。例如:
fid = fopen('data.txt', 'w');
fprintf(fid, '%d\n', 1);
fprintf(fid, '%d\n', 2);
fclose(fid);
这样就可以将数字 1 和 2 写入 data.txt 文件,并在它们之间添加一个换行符。
matlab向 txt中写入空格并换行
可以使用 fprintf 函数将数据写入 txt 文件中,例如:
```matlab
fid = fopen('data.txt', 'w');
fprintf(fid, '%d %d\n', 1, 2);
fprintf(fid, '%d %d\n', 3, 4);
fclose(fid);
```
这样就可以将数据 1 2 和 3 4 写入 data.txt 文件中,并在每行末尾添加空格和换行符。