import time and data from excel
2 次查看(过去 30 天)
显示 更早的评论
Dear All,
I am facing a seemingly simple problem. I have data in the following format:
date var
01.01.2000 13
01.04.2000 15
...
in Excel and want to import it in Matlab such that date becomes a date vector and var a numbers vector. The matlab import function and another thread in this forum led me to:
[~, ~, raw] = xlsread('\data\sandbox.xlsx','Tabelle1','A2:B9');
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
cellVectors = raw(:,1);
raw = raw(:,2);
data = reshape([raw{:}],size(raw));
date1 = cellVectors(:,1);
ARBANS010010 = data(:,1);
clearvars data raw cellVectors;
str = datestr( date1, 'DD/MM/YYYY' );
num = datenum( str,'DD/MM/YYYY' );
which produces an error. A minimum example is attached to this post. If you download the excel file and run my code you should get the same error. I am somewhat confused. My dates are not even in a weird format or something. Looks like a straight forward thing to do for matlab?
If anyone can produce code that succesfully imports the data or points me towards what I fail at seeing here, I would really appreciate it!
Thanks in advance!
0 个评论
回答(1 个)
Andrei Bobrov
2016-5-26
[n,st] = xlsread('sandbox.xlsx',1,'A2:B9');
out = [datenum(st,'dd.mm.yyyy'),n];
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!