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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146601/image.jpeg)
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!