필터 지우기
필터 지우기

How to plot a timeseries from excel table

조회 수: 37 (최근 30일)
Elliot Jenkins
Elliot Jenkins 2023년 3월 15일
답변: Amit Dhakite 2023년 3월 16일
Hi there,
I want to plot a time series of a two column table from excel. The date format is 'mm-yyyy'. I keep getting an invalid plot argument error. I have attached the table I am trying to plot below.
Thank you

답변 (1개)

Amit Dhakite
Amit Dhakite 2023년 3월 16일
Hello Elliot,
Based on your description, it seems that you are trying to plot a timeseries from an Excel table, but are encountering an error due to the "mm_yyyy" column being of type "cell". Since a cell type is not a valid input for the plot function, we need to convert it to a proper timeseries type.
To resolve this issue, we can use the readtable function to read the data from the Excel sheet, and then convert the "mm_yyyy" column to a "timeseries" type using the datetime function with the appropriate input format. Once this is done, we can plot the data using the plot function.
Here is the updated code to perform the conversion and plotting:
% Reading the data from excel sheet
data = readtable('SGIdata.xlsx');
% Converting the "mm_yyyy" column from a "cell" type to a "timeseries" type
data.mm_yyyy = datetime(data.mm_yyyy, 'InputFormat', 'mm-yyyy');
% Plotting the data
plot(data.mm_yyyy, data.SGI);
To know more about the functions used above, kindly refer to the following links:
  1. readtable(): https://www.mathworks.com/help/matlab/ref/readtable.html
  2. datetime(): https://www.mathworks.com/help/matlab/ref/datetime.html
  3. plot(): https://www.mathworks.com/help/matlab/ref/plot.html

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by