How to get matlab import to see col with nan as number
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Azzi Abdelmalek
2014-12-26
编辑:Azzi Abdelmalek
2014-12-26
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 个评论
更多回答(1 个)
Star Strider
2014-12-26
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!