필터 지우기
필터 지우기

import time and data from excel

조회 수: 2 (최근 30일)
roblocks
roblocks 2016년 5월 26일
댓글: roblocks 2016년 5월 26일
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!

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 5월 26일
[n,st] = xlsread('sandbox.xlsx',1,'A2:B9');
out = [datenum(st,'dd.mm.yyyy'),n];
  댓글 수: 3
roblocks
roblocks 2016년 5월 26일
ah I think I now what you mean:
[n,st] = xlsread('\data\sandbox.xlsx',1,'A2:B9');
time = datenum(st,'dd.mm.yyyy');
date_d = datetime(time, 'ConvertFrom', 'Excel', 'Format', 'mm/dd/yyyy');
So finally I am now trying to get it in quarterly format. Changing to q/yyyy messes things up though.
roblocks
roblocks 2016년 5월 26일
It is weird.
[n,st] = xlsread('\data\sandbox.xlsx',1,'A2:B9');
time = datenum(st,'dd.MM.yyyy');
a= datevec(time)
c=datetime(a, 'Format', 'dd/MM/yyyy')
Now c is different from st... somehow it loses information along the way...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by