[英]Asking for input file that contain string in octave
I am trying to load data from a csv file. 我正在尝试从csv文件加载数据。 I have been told to use textscan
, but when I try to load the file using csvread
I get the error "undefined near line 1 column 16". 有人告诉我使用textscan
,但是当我尝试使用csvread
加载文件时,出现错误“第1行第16列附近未定义”。 I get the same error, but with different column position, when trying to use similar methods such as fileread
and textread
. 当尝试使用类似的方法(如fileread
和textread
时,出现相同的错误,但列位置不同。
Here is the link to the csv file https://drive.google.com/open?id=0ByD1GZqyS54ZV3ZoVFltYzZ6eE0 and here is a picture of the file . 这是csv文件https://drive.google.com/open?id=0ByD1GZqyS54ZV3ZoVFltYzZ6eE0的链接,这是该文件的图片 。
I know it would be easier to simply remove the other, unwanted content, because I just need the data from columns E, F, G, and K, and could then use dlmread
or csvread
on these numeric values. 我知道简单地删除其他不需要的内容会更容易,因为我只需要E,F,G和K列中的数据,然后可以在这些数字值上使用dlmread
或csvread
。 Still, this does not seem like it should be that hard. 尽管如此,这似乎并不应该那么难。 Can you please help me understand how to load string data from a file in with MATLAB or Octave? 您能帮我了解如何使用MATLAB或Octave从文件中加载字符串数据吗?
Update 08/20/17 (UTC+7) 更新08/20/17(UTC + 7)
thanks for the answer, especially from information (this is userid right?) 感谢您的回答,尤其是信息方面的回答(这是用户ID吗?)
i think the problem probably cause by the first row that have 26 cells and the other 4 just 20, so i decide to remove data after column K and we have 11 column and then run : 我认为问题可能是由第一行有26个单元格而其他4个只有20个单元格引起的,所以我决定在K列之后删除数据,然后我们有11列,然后运行:
fid=fopen('tesdata.dat'); FID =的fopen( 'tesdata.dat'); %i change the data in csv to dat file %i将csv中的数据更改为dat文件
c=textscan(fid,'%f%s%s%s%f%f%d8%s%s%s%f'); C = textscan(FID, '%F%S%S%S%F%F%D8%S%S%S%F');
fclose(fid); FCLOSE(FID);
this works for my case, so i think the problem probably the different column size. 这适用于我的情况,所以我认为问题可能出在不同的列大小上。 well i do think this could work if the file in csv with csvread 好吧,我确实认为如果使用csvread的csv中的文件可以这样做
[num,txt,raw] = xlsread(filename) [num,txt,raw] = xlsread(文件名)
you can use this. 你可以用这个 use data present in raw 使用原始数据
raw{:,5}, raw{:,6}, raw{:,7}, raw{:,11} 原始{:,5},原始{:,6},原始{:,7},原始{:,11}
is what you need 是你所需要的
Here's a textscan
solution to grab each column as a string. 这是一个textscan
解决方案,用于将每一列作为字符串获取。
fname = 'katalogisc.csv'; % your file
fid = fopen(fname,'r');
numCols = 'Z'-'A'+1; % i.e. 26 columns in this case
scanStr = repmat('%s',1, numCols); % interpret each column as a string
columnsOfStrings = textscan(fid, scanStr,'delimiter',','); % split strings by comma (,)
fclose(fid);
I like the xlsread
solution when it works, but get a 'File is not recognized format' error, in this case, on my machine. 我喜欢xlsread
解决方案,但在这种情况下,我的计算机上出现了“文件无法识别格式”错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.