How to get matlab import to see col with nan as number
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Daniel
el 26 de Dic. de 2014
Respondida: Star Strider
el 26 de Dic. de 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.
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 26 de Dic. de 2014
Editada: Azzi Abdelmalek
el 26 de Dic. de 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,[])'
0 comentarios
Más respuestas (1)
Star Strider
el 26 de Dic. de 2014
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.
0 comentarios
Ver también
Categorías
Más información sobre Large Files and Big Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!