matlab读寫文件--bin/txt/csv
来源:互联网 发布:淘宝长尾词怎么找 编辑:程序博客网 时间:2024/06/07 13:32
matlab学习笔记
保存和读取二进制文件.bin
注:元素按列保存
%% write and saveA = rand(3,4,'single');fid = fopen('Asave.bin', 'wb');fwrite(fid, A, 'single');%(句柄,变量,精度)fclose(fid);%% test and readfidtest = fopen('Asave.bin', 'r');while ~feof(fidtest) dataTen = fread(fidtest,'single');endfclose(fidtest);
以上保存的是很簡單的數據,在實際應用時會發現會有不同的需求。在這裏只是簡單的記錄下平常用到的功能,比較片面,還是matlab doc大法好,多查多看。
寫入txt文件
x = 0:.1:1;A = [x; exp(x)];fileID = fopen('exp.txt','w');fprintf(fileID,'%6s %12s\n','x','exp(x)');fprintf(fileID,'%6.2f %12.8f\n',A);fclose(fileID);
讀取包含數字和字符的CSV文件
reference:http://www.ilovematlab.cn/thread-115241-1-1.html
%本文件用于含表头的csv文件读取,数据返回格式为cell类型和int32数据类型clear;close all;%打开csv文件fid = fopen('20101231.csv');%读取表头 数据返回为cell类型 调用格式title{1}title = textscan(fid, '%s %s %s %s %s %s %s %s %s %s',1,'delimiter', ',')%读取数据 返回为cell类型data = textscan(fid, '%s %d32 %d32 %d32 %d32 %d32 %d32 %d32 %d32 %d32','delimiter', ',')fclose(fid);
常用函數及參數說明
fopen — Open file, or obtain information about open files
1.fileID = fopen(filename) % returns an integer file identifier equal to or greater than 3 % If fopen cannot open the file, then fileID is -12. fileID = fopen(filename,permission) % permission means file access type, such as 'r'(default), 'w+', 'a+', 'A', 'W' and so on . % 後面幾個不怎麼用到3. fileID = fopen(filename,permission,machinefmt,encodingIn)4. [fileID,errmsg] = fopen(___)5. fIDs = fopen('all')6. ...
fprint — Write data to text file
1.fprintf(fileID,formatSpec,A1,...,An)2.fprintf(formatSpec,A1,...,An) % Print multiple numeric values and literal text to the screen.
example:
A1 = [9.9, 9900];A2 = [8.8, 7.7 ; ... 8800, 7700];formatSpec = 'X is %4.2f meters or %8.3f mm\n';fprintf(formatSpec,A1,A2)
screen will display:
X is 9.90 meters or 9900.000 mm
X is 8.80 meters or 8800.000 mm
X is 7.70 meters or 7700.000 mm
0 0
- matlab读寫文件--bin/txt/csv
- matlab读txt文件
- 读取文件(.txt、.excel、.csv),在c++、matlab环境中
- MatLab中读取TXT文件和bin文件,存储bin文件
- R读.csv,.txt,xlsx文件
- 读取.txt .csv文件
- 读取csv.txt文件
- txt,csv文件存储
- Matlab读取CSV文件
- Matlab读取CSV文件
- Matlab读取CSV文件
- matlab读取csv文件
- matlab文件操作及读txt文件
- matlab文件操作及读txt文件
- matlab文件操作及读txt文件
- matlab文件操作及读txt文件
- Matlab文件操作及读txt文件
- Matlab文件操作及读txt文件
- 试验插入图片,看来要公司网络限制,需要使用邮箱等无限制的途径作为在线笔记!!
- my_strcmp
- LINUX 文件操作
- MySQL之——基于Keepalived实现双机HA
- CentOS安装scp命令
- matlab读寫文件--bin/txt/csv
- 海淘thinkpad-t460p攻略
- 移动设备无线投屏到电视机
- T-SQL基础知识
- Web Service概述
- HDU2033引发的关于运算符优先级
- CentOS安装sysstat命令
- codeforces 731C 并查集
- 扩展欧几里得