matlab写文件与导出数据(fprintf,dlmwrite,xlswrite)
来源:互联网 发布:源码怎么使用 编辑:程序博客网 时间:2024/06/05 08:09
1. 用fprintf 函数写数据到txt,xls
Example:
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'w');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid)
tip:执行上述代码执行,肯定不会换行的,换行的问题试一下下面的代码x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid);
这次就没有问题了,我们要注意fopne的参数wt 而不是 w,这是matlab的在线帮助的东东
fid = fopen(filename, permission_tmode) on Windows systems, opens the file in text
mode instead of binary mode (the default). The permission_tmode argument consists
of any of the specifiers shown in the Permission Specifiers table above, followed
by the letter t, for example 'rt' or 'wt+. On UNIX? systems, text and binary mode
are the same. (UNIX is a registered trademark of The
Open Group in the United States and other countries).
就是有两种读取模式binary or text. When choosing the binary model,No characters are
given special treatment. 所以我们选择要注明text模式。
2. dlmwrite :将一个矩阵写到由分隔符分割的文件中。
在保存整数到文件时使用save存为ascii文件时,常常是文件里都是实型格式的数据(有小数点,和后面很多的0,看着很不方便)。于是要保存此类数据时,我们可以使用此dlmwrite命令。
使用方法:
dlmwrite('filename', M)
使用默认分隔符“,”将矩阵M写入文本文件filename中;
dlmwrite('filename', M, 'D')
使用分隔符D分割数据,“\t”表示tab分割,“,”为默认分割符;
dlmwrite('filename', M, 'D', R, C)
从矩阵M的第R行、第C列开始,作为要写矩阵块的左上角,将数据用D分割写入文件。
其他用法有:
dlmwrite('filename', M, 'attrib1', value1, 'attrib2', value2, ...)
dlmwrite('filename', M, '-append')
dlmwrite('filename', M, '-append', attribute-value list)
例如:
a = [1 2 3; 4 5 6; 7 8 9];
dlmwrite('test.txt', a);
则test.txt中的内容为:
1,2,3
4,5,6
7,8,9
而使用save
a = [1 2 3; 4 5 6; 7 8 9];
save 'tst.txt' a -ascii;
文本文件里的内容为:
1.0000000e+000 2.0000000e+000 3.0000000e+000
4.0000000e+000 5.0000000e+000 6.0000000e+000
7.0000000e+000 8.0000000e+000 9.0000000e+000
3.xlswrite 写入excel
4.fprintf和dlmwrite区别
MATLAB在图像处理中的应用,实际是对图像矩阵的操做运算,MATLAB在图像处理中的常用的命令有:
imread(): 从图像文件夹中读取图像的函数;
imwrite(): 输出图像的函数;
imshow(), image(): 图像显示于屏幕的函数;
imcrop(): 对图像进行裁剪的函数;;
imresize(): 实现对图像的插值缩放的函数;
imrotate(): 用实现对图像的旋转。
im2double(),double(): 将图像数组转化为double类型;
im2uint8(),uint8(): 将图像数组转化为uint8类型;
im2uint16(),uint16(): 将图像数组转化为uint16类型;
关于上述的命令使用方法可以参考一些MATLAB方面的书籍或者用MATLAB自带的帮助(help or doc)命令.
如 我想知道dwt2()命令的使用方法 可以执行下面的命令
>> help dwt2 或 >>doc dwt2
系统就会告诉你它的使用要求和方法,如果系统说找不到对应的帮助文件,那就可能是你装的MATLAB里面没有这个命令,那很可能这个命令就不能使用.在图像数组的输出到文件的操作上,我发现fprintf比dlmwrite明显快很多,但这两个输出的数据格式有些差别,见下面操作:
>> a=[1 2 3;4 5 6;7 8 9]a =
1 2 3
4 5 6
7 8 9
>>fid = fopen('exp.txt','w');
fprintf(fid,'%2.0f\n',a);
fclose(fid);
>> type exp.txt
1
4
7
2
5
8
3
6
9
fprintf输出是一列一列的从左到右输出。
>> dlmwrite('eg2.dat',a,'\n');
>> type eg2.dat1
2
3
4
5
6
7
8
9
dlmwrite输出是一行一行的从上到下输出。下面是一个比较简单的图像处理程序:
clear;%清除当前工作区所有变量
data=imread('E:\2D前处理\eg1.bmp');%从图像文件夹中读取图像eg1.bmp
data=double(data);%将图像数组data转化为double类型
[x,y]=size(data);%求数组大小,x是data数组有多少行,y是data数组有多少列
data1=imresize(data,[x,y*2/1.732]);%实现对图像的左右插值放大2/1.732倍
[x,y]=size(data1);%%求放大后图像数组大小
fid = fopen('E:\2D前处理\Particle\test.dat', 'wt');%打开图像数组的将要输出到文件
fprintf(fid, '%2.0f\t%2.0f\n', x, y);%输出x,y值
fprintf(fid, '%2.0f\n', data1);%输出图像数组数据
fclose(fid);%关闭文件指针
1. 用fprintf 函数写数据到txt,xls
Example:
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'w');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid)
tip:执行上述代码执行,肯定不会换行的,换行的问题试一下下面的代码x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');
fprintf(fid, '%6.2f %12.8f\n', y);
fclose(fid);
这次就没有问题了,我们要注意fopne的参数wt 而不是 w,这是matlab的在线帮助的东东
fid = fopen(filename, permission_tmode) on Windows systems, opens the file in text
mode instead of binary mode (the default). The permission_tmode argument consists
of any of the specifiers shown in the Permission Specifiers table above, followed
by the letter t, for example 'rt' or 'wt+. On UNIX? systems, text and binary mode
are the same. (UNIX is a registered trademark of The
Open Group in the United States and other countries).
就是有两种读取模式binary or text. When choosing the binary model,No characters are
given special treatment. 所以我们选择要注明text模式。
2. dlmwrite :将一个矩阵写到由分隔符分割的文件中。
在保存整数到文件时使用save存为ascii文件时,常常是文件里都是实型格式的数据(有小数点,和后面很多的0,看着很不方便)。于是要保存此类数据时,我们可以使用此dlmwrite命令。
使用方法:
dlmwrite('filename', M)
使用默认分隔符“,”将矩阵M写入文本文件filename中;
dlmwrite('filename', M, 'D')
使用分隔符D分割数据,“\t”表示tab分割,“,”为默认分割符;
dlmwrite('filename', M, 'D', R, C)
从矩阵M的第R行、第C列开始,作为要写矩阵块的左上角,将数据用D分割写入文件。
其他用法有:
dlmwrite('filename', M, 'attrib1', value1, 'attrib2', value2, ...)
dlmwrite('filename', M, '-append')
dlmwrite('filename', M, '-append', attribute-value list)
例如:
a = [1 2 3; 4 5 6; 7 8 9];
dlmwrite('test.txt', a);
则test.txt中的内容为:
1,2,3
4,5,6
7,8,9
而使用save
a = [1 2 3; 4 5 6; 7 8 9];
save 'tst.txt' a -ascii;
文本文件里的内容为:
1.0000000e+000 2.0000000e+000 3.0000000e+000
4.0000000e+000 5.0000000e+000 6.0000000e+000
7.0000000e+000 8.0000000e+000 9.0000000e+000
3.xlswrite 写入excel
4.fprintf和dlmwrite区别
MATLAB在图像处理中的应用,实际是对图像矩阵的操做运算,MATLAB在图像处理中的常用的命令有:
imread(): 从图像文件夹中读取图像的函数;
imwrite(): 输出图像的函数;
imshow(), image(): 图像显示于屏幕的函数;
imcrop(): 对图像进行裁剪的函数;;
imresize(): 实现对图像的插值缩放的函数;
imrotate(): 用实现对图像的旋转。
im2double(),double(): 将图像数组转化为double类型;
im2uint8(),uint8(): 将图像数组转化为uint8类型;
im2uint16(),uint16(): 将图像数组转化为uint16类型;
关于上述的命令使用方法可以参考一些MATLAB方面的书籍或者用MATLAB自带的帮助(help or doc)命令.
如 我想知道dwt2()命令的使用方法 可以执行下面的命令
>> help dwt2 或 >>doc dwt2
系统就会告诉你它的使用要求和方法,如果系统说找不到对应的帮助文件,那就可能是你装的MATLAB里面没有这个命令,那很可能这个命令就不能使用.在图像数组的输出到文件的操作上,我发现fprintf比dlmwrite明显快很多,但这两个输出的数据格式有些差别,见下面操作:
>> a=[1 2 3;4 5 6;7 8 9]a =
1 2 3
4 5 6
7 8 9
>>fid = fopen('exp.txt','w');
fprintf(fid,'%2.0f\n',a);
fclose(fid);
>> type exp.txt
1
4
7
2
5
8
3
6
9
fprintf输出是一列一列的从左到右输出。
>> dlmwrite('eg2.dat',a,'\n');
>> type eg2.dat1
2
3
4
5
6
7
8
9
dlmwrite输出是一行一行的从上到下输出。下面是一个比较简单的图像处理程序:
clear;%清除当前工作区所有变量
data=imread('E:\2D前处理\eg1.bmp');%从图像文件夹中读取图像eg1.bmp
data=double(data);%将图像数组data转化为double类型
[x,y]=size(data);%求数组大小,x是data数组有多少行,y是data数组有多少列
data1=imresize(data,[x,y*2/1.732]);%实现对图像的左右插值放大2/1.732倍
[x,y]=size(data1);%%求放大后图像数组大小
fid = fopen('E:\2D前处理\Particle\test.dat', 'wt');%打开图像数组的将要输出到文件
fprintf(fid, '%2.0f\t%2.0f\n', x, y);%输出x,y值
fprintf(fid, '%2.0f\n', data1);%输出图像数组数据
fclose(fid);%关闭文件指针
- matlab写文件与导出数据(fprintf,dlmwrite,xlswrite)
- matlab导出数据(fprintf,dlmwrite,xlswrite)
- MATLAB 输出函数及导出数据(dispfprintf,dlmwrite,xlswrite)
- MATLAB ——输出函数及导出数据(dispfprintf,dlmwrite,xlswrite
- Matlab之保存/写矩阵数据到文本(fprintf, save, dlmwrite)
- MATLAB文件操作之fopen与fprintf
- 关于MATLAB中xlswrite函数写数据出现服务器异常情况的解决办法
- matlab中xlswrite函数写数据出现服务器异常情况的解决办法
- matlab与excel xlsread、xlswrite实用方法
- fprintf写文件
- Matlab文件和数据的导入与导出
- Matlab文件和数据的导入与导出
- Matlab文件和数据的导入与导出
- Matlab文件和数据的导入与导出
- c++中用fprintf写文件
- matlab xlswrite 用法以及实例(转自“百度经验”)
- MATLAB中从.fig文件导出数据
- MATLAB fprintf
- vuejs标签切换demo
- mysql lower_case_table_names 参数引起的一起事故
- C# winform点击生成二维码
- oracle中merge into..using..on..when..when..用法
- 用枚举实现单例
- matlab写文件与导出数据(fprintf,dlmwrite,xlswrite)
- SpringMVC注解实现登录验证
- 插入排序法
- 第2章 关系模型介绍
- 北大ACM试题分类
- iOS 清除通知中心收到的APNS通知
- Kafka初识
- easyui 请求超时,如何重定向至登录页面
- cocos2D CCSprite 4