0
votes

I am trying to load data from a csv file. 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". I get the same error, but with different column position, when trying to use similar methods such as fileread and textread.

Here is the link to the csv file https://drive.google.com/open?id=0ByD1GZqyS54ZV3ZoVFltYzZ6eE0 and here is a picture of the file.

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. 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?

Update 08/20/17 (UTC+7)

thanks for the answer, especially from information (this is userid right?)

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 :

fid=fopen('tesdata.dat'); %i change the data in csv to dat file

c=textscan(fid,'%f%s%s%s%f%f%d8%s%s%s%f');

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

2
please show your code with textscan and what you've done so farAndy

2 Answers

0
votes

Here's a textscan solution to grab each column as a string.

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.

1
votes

[num,txt,raw] = xlsread(filename)

you can use this. use data present in raw

raw{:,5}, raw{:,6}, raw{:,7}, raw{:,11}

is what you need