在matlab中从CSV文件中读取特定列 [英] Reading specific column from CSV file in matlab
问题描述
我想在matlab中读取CSV文件。我只想读第二列,但下面的代码打印出CSV文件中的一切。我有哪些参数或功能引入,使其只读取第二列
FILENAME ='C:\Users\ Desktop\Results.csv';
fid = fopen(FILENAME,'rt');
a = textscan(fid,'%s','HeaderLines',1,'Delimiter',',');
fclose(fid);
celldisp(一)
有几个方法:
-
使用
中有cvsread
:
假设您在文件 1N
行:a = csvread(FILENAME,0,1,[0 1 N-1 1]);
-
您也可以考虑
xlsread
a = xlsread(FILENAME,'B:B');
查看具体例如中的
xlsread
文档。 -
另一个选择是
dlmread
A = dlmread( FILENAME,',',[0 1 N-1 1]);
1 - 一个很好的(和快速)的方法来计算在Matlab文件中的行可以的这个回答由Rody Oldenhuis 。
I am trying to read a CSV file in matlab. I just want to read the second column but the code below prints out everything on CSV file. What parameters or functions I have to introduce to make it read just the second column
FILENAME = 'C:\Users\Desktop\Results.csv';
fid = fopen(FILENAME, 'rt');
a = textscan(fid, '%s', 'HeaderLines',1,'Delimiter',',');
fclose(fid);
celldisp(a)
There are several ways:
Using
cvsread
:
Assuming you haveN
rows in the file1:a = csvread( FILENAME, 0, 1, [0 1 N-1 1 ] );
You might also consider
xlsread
a = xlsread( FILENAME, 'B:B' );
See specific example on the
xlsread
doc.Another option is
dlmread
a = dlmread( FILENAME, ',', [0 1 N-1 1] );
1 - A nice (and fast) way to count the number of lines in the file in Matlab can be found in this answer by Rody Oldenhuis.
这篇关于在matlab中从CSV文件中读取特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!