How to get matlab import to see col with nan as number

1 vue (au cours des 30 derniers jours)
Daniel
Daniel le 26 Déc 2014
I'm using R2014a. I have a comma deliminted text file of data. The first row are headers. The first column is in a date time format which I eventually want to convert to seconds from a reference time. The rest of the file is either numbers or nan. I'm using the Matlab import routine to import the data as column vectors. If there is an nan in a column, it wants to import that col. as TEXT and creates a CELL array rather than a DOUBLE. I can manually select NUMBER from the drop down on the import screen and it seems to be fine with that, but it's a hassle to go through every column, everytime I import.
I thought I could convert the column cell arrays to numeric vectors but the mat2cell gives me an error. Error in cell2mat (line 83) m{n} = cat(1,c{:,n});
How can I get all the variables (except perhaps the date/time) into a numeric format? I've attached a truncated file as an example and a screen shot of the import.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 26 Déc 2014
Modifié(e) : Azzi Abdelmalek le 26 Déc 2014
d=importdata('import_test.csv')
h=d.textdata;
header=h(1,:)
yourdate=h(2:end,1)
YourData=d.data
%or
[a,b,c]=xlsread('import_test.csv')
m=regexp(b,',','split')
YourData=reshape([m{:}],99,[])'

Plus de réponses (1)

Star Strider
Star Strider le 26 Déc 2014
Use the textscan function:
cu = (double('C')-double('A')+1) * 26 + double('U')-double('A')+1 ;
fidi = fopen('Daniel_import_test.csv');
[d] = textscan(fidi, ['%s' repmat('%f',1,cu-1)], 'HeaderLines',1, 'Delimiter',',', 'CollectOutput',1)
chkd = d{2}(1:10, 1:10) % Peek At The Imported Data
The temporary ‘chkd’ variable lets you peek at the numeric data textscan imports. Note that it imports the date and time as a cell string (I told it to), so you can convert those later with datenum.

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by