matlab导入CSV文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab导入CSV文件相关的知识,希望对你有一定的参考价值。
如何将CSV格式文件里的数据导入到matlab程序中?就是用matlab直接调用CSV里的数据~~~求具体语句~~~
尝试了import data,比如我插入的文档是DOW.txt,尝试了之后就会提示我
Error in ==> importfile at 9
newData1 = importdata(DOW.txt);
??? Undefined variable "DOW" or class "DOW.txt".
要在哪个地方定义dow呢?
这是matlab插入之后自动产生的:
function importfile(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 16-Apr-2008 17:59:56
% Import the file
newData1 = importdata(DOW.txt);
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', varsi, newData1.(varsi));
end
请问我要如何定义参数?
matlab便会将DOW.txt看成是变量,但是importdata需要一个包含文件名的字符串变量,但是DOW.txt不知道是什么东西,所以会出现??? Undefined variable "DOW" or class "DOW.txt".
正确的使用方法是:
newData1 = importdata('DOW.txt');
或者
path='DOW.txt'
newData1 = importdata(path);
不过importdata不支持后缀名为txt文件,其支持的文件后缀有:
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 dlmread Double array.
Spreadsheet formats
XLS - Excel worksheet xlsread Double array and cell array.
WK1 - Lotus 123 worksheet wk1read Double array and cell array.
Scientific data formats
CDF - Common Data Format cdfread Cell array of CDF records
FITS - Flexible Image Transport System fitsread Primary or extension table data
HDF - Hierarchical Data Format hdfread HDF or HDF-EOS data set
Movie formats
AVI - Movie aviread MATLAB movie.
Image formats
TIFF - TIFF image imread Truecolor, grayscale or indexed image(s).
PNG - PNG image imread Truecolor, grayscale or indexed image.
HDF - HDF image imread Truecolor or indexed image(s).
BMP - BMP image imread Truecolor or indexed image.
JPEG - JPEG image imread Truecolor or grayscale image.
GIF - GIF image imread Indexed image.
PCX - PCX image imread Indexed image.
XWD - XWD image imread Indexed image.
CUR - Cursor image imread Indexed image.
ICO - Icon image imread Indexed image.
RAS - Sun raster image imread Truecolor or indexed.
PBM - PBM image imread Grayscale image.
PGM - PGM image imread Grayscale image.
PPM - PPM image imread Truecolor image.
Audio formats
AU - NeXT/Sun sound auread Sound data and sample rate.
SND - NeXT/Sun sound auread Sound data and sample rate.
WAV - Microsoft Wave sound wavread Sound data and sample rate.
参考资料:matlab帮助文档
参考技术A 菜单里Files -> Import data...你的csv文件是怎样的?csv文件里应该只有数据,没有其他任何东西。
以上是关于matlab导入CSV文件的主要内容,如果未能解决你的问题,请参考以下文章