简体   繁体   English

使用ezread读取.csv文件时出现问题

[英]Problems reading a .csv file with ezread

I was trying to read a csv file with ezread https://de.mathworks.com/matlabcentral/fileexchange/11026-ezread and I get the following problem: 我试图用ezread https://de.mathworks.com/matlabcentral/fileexchange/11026-ezread读取csv文件,我遇到以下问题:

Error using textscan The second input must be a format character vector containing at least one >specifier or a literal field. 使用textscan时出错第二个输入必须是包含至少一个>说明符或文字字段的格式字符向量。

Error in ezread (line 66) data = textscan(fid,format_str,'delimiter',file_delim,'headerlines',1); ezread错误(第66行)data = textscan(fid,format_str,'delimiter',file_delim,'headerlines',1);

I call the function as follows: 我把这个函数调用如下:

tmpName = '/path/file.csv';
structRead = ezread(tmpName, 'r');

I have checked if tmpName is correct with isfile() , so it is a correct path. 我已检查tmpName是否与isfile()一致 ,因此它是一个正确的路径。
First two rows of my file have the following format: 我文件的前两行具有以下格式:

a,b,c,d
1,2,e,f

Do you know where the problem could be ? 你知道问题出在哪里吗?

Instead ezread , you should use importdata . 相反, ezread ,你应该使用importdata However it will not recognize separation on comma , . 但它不会识别逗号分隔, So you need to add extra line: 所以你需要添加额外的行:

tmpName = importdata('/path/file.csv');
structRead = split(a, ',')

The result is: 结果是:

2×4 cell array

  {'a'}    {'b'}    {'c'}    {'d'}
  {'1'}    {'2'}    {'e'}    {'f'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM