Plot serial date of excel into MATLAB

1 Ansicht (letzte 30 Tage)
Md Mizanur Raihan
Md Mizanur Raihan am 6 Okt. 2020
Beantwortet: Seth Furman am 22 Okt. 2020
Hi, WOuld you please help me? 1st column represents serial date like year 2001 month 12 and date 16 and second coulm represents height. I would like to run and plot my data in following format:
data_set=xlsread('h100.xlsx');
figure;
plot(data_set(:,1),data_set(:,2));
grid on;
xlim([datenum('1 oct 2010') datenum('1 dec 2010')])
datetick('keeplimits')
xlabel('Time Series');
ylabel('Tidal heights');
title('Original Data Set (Richard Bay, SA)');
.
  2 Kommentare
Sudhakar Shinde
Sudhakar Shinde am 6 Okt. 2020
Bearbeitet: Sudhakar Shinde am 6 Okt. 2020
What is the error you observed?
You can use date from excel sheet column 1.
x = datetime(data_set(:,1),'ConvertFrom','yyyymmdd');
plot(x,data_set(:,2));
Md Mizanur Raihan
Md Mizanur Raihan am 6 Okt. 2020
It is showing as output

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Star Strider
Star Strider am 6 Okt. 2020
The first column is numeric representation of yyyymmdd so there are likely several ways to create a datetime array from it.
Try this:
data_set(:,1) = [20011216; 20011217];
ymdc = compose('%d',data_set(:,1));
ymd = datetime(ymdc, 'InputFormat','yyyyMMdd')
You can put those in one line if you want:
ymd = datetime(compose('%d',data_set(:,1)), 'InputFormat','yyyyMMdd')
.

Seth Furman
Seth Furman am 22 Okt. 2020
Do also prefer using readtable and readtimetable as opposed to xlsread.

Kategorien

Mehr zu Time Series Objects finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by