使用csvread函数读取
M = csvread('filename')
M = csvread('filename', row, col)
M = csvread('filename', row, col, range)
输出用:
csvwrite('filename',M)
csvwrite('filename',M,row,col)
实际使用时importdata()函数比较方便,从Excel另存数据为"csv"文件,matlab在读取时容易产生如下错误:
??? Error using ==> dlmread at 145
Mismatch between file and format string.
Trouble reading number from file (row 1, field 2) ==> " -0.
Error in ==> csvread at 52
m=dlmread(filename, ',', r, c);
Data formats Command Returns
MAT - MATLAB workspace load Variables in file.
CSV - Comma separated numbers csvread Double array.
DAT - Formatted text importdata Double array.
DLM - Delimited text dlmread Double array.
TAB - Tab separated text dlmre