I wanted to use [~, ~, temp] = xlsread('1.csv','A:A');
to get the first column of the 1-line CSV file 1.csv
.
1.csv
contains just one line:
5B0E8795E18013D0FBC33558F0512832,3,7,1,Practice,Juicer,Juicer,true,false,2347.0,0
However the returned temp
is a <1048576x1> cell. Shouldn't temp
be a <1x1> cell?
The parameter 'A:A'
should return only the existing rows of the first column, as shown in the "Read a Column of Data" example in the xlsread() documentation. Since temp
is a <1048576x1> cell, it seems like using 'A:A'
returns the entire column, including the non-existing rows (1048576 is the maximum number of rows in Microsoft Excel 2010).
Using textscan()
works fine (= datatemp
in the following snippet will have only 1 row):
fid = fopen('1.csv','r');
datatemp = textscan(fid, '%s %d %d %d %s %s %s %s %s %d %d', 'delimiter',',', 'CollectOutput',true)
fclose(fid);
However I don't understand why xlsread()
fails to work properly. I use MATLAB R2012a 64-bit, Microsoft Excel 2010 and Windows 7 x64.
That's actually how the Excel COM interface works, so you can't blame MATLAB :)
Here is a sample code that basically does what
xlsread
internally. You could write the code in VBScript/Powershell and get the same result...The variable
val
returned:where all cells except the first one are NaNs:
I dont understand why you dont just use
textscan
to parse the file as text, which is much faster than invoking COM (Not to mention portable to other platforms other than Windows)