Unable to plot data from .xlsx

I want to plot data from .xlsx (or .csv) file. I have used the following code. earlier I had also used round braces in line 2 and 3 but that didn't work as well. It gave the error message "Tables and timetables do not have a plot method. To plot a table or a timetable, use the stackedplot function. As an alternative, extract table or timetable variables using dot or brace subscripting, and then pass the variables as input arguments to the plot function." After using curly braces now the error message is "Error using plot Invalid data argument." The data file has around 2 Million *22 enteries. Any function that converts it into a matrix would be helpful. Thanks in advance
T =readtable('PuneAQMNew_22.xlsx');
Time=T{:,16};
AirQuality= T{:,2};
plot(AirQuality,Time,'r')
legend('Airquality')

9 件のコメント

Walter Roberson
Walter Roberson 2022 年 8 月 17 日
The code you have now should work, provided that column 2 and 16 are numeric (such as double), or are categorical, or are duration objects, or are datetime objects.
whos Time AirQuality
Shweta Kiran
Shweta Kiran 2022 年 8 月 17 日
Air Quality is an integer number whereas time is in the form HH:MM:SS.
Walter Roberson
Walter Roberson 2022 年 8 月 17 日
Is Time duration objects, or datetime objects, or cell array of character vectors?
Shweta Kiran
Shweta Kiran 2022 年 8 月 17 日
移動済み: Voss 2022 年 8 月 19 日
I am sorry I don't know how to identify if it is any of these. One example of the Time entry is 00:01:43.
Walter Roberson
Walter Roberson 2022 年 8 月 17 日
移動済み: Voss 2022 年 8 月 19 日
What shows up for
class(Time)
Shweta Kiran
Shweta Kiran 2022 年 8 月 18 日
移動済み: Voss 2022 年 8 月 19 日
class of Time is double whereas class of AirQuality is cell.
Walter Roberson
Walter Roberson 2022 年 8 月 18 日
移動済み: Voss 2022 年 8 月 19 日
Earlier you indicated that AirQuality is integer; now you say it is cell. Does that mean that each entry in the table for AirQuality is a cell array containing a single integer in numeric form (class double)?
If so, at the moment I cannot think of any way that readtable() could have produced such a table. I can think of cases in which it could have produced a table in which the column was a cell array in which each entry was a character vector that represented a number. That can happen if there are extra headers in the file; there are a couple of possible work-arounds for that. It can also happen if somewhere in the column there is text other than "NaN" -- for example if there is an entry saying "missing" or "N/A", or if there is some kind of summary area at the bottom of the file.
Shweta Kiran
Shweta Kiran 2022 年 8 月 19 日
移動済み: Voss 2022 年 8 月 19 日
I have csv and xlsx files for the same data. If I use the csv file the script runs fine whereas it shows the errors mentioned above for the xlsx files. The class type of Air Quality is double and time is duration in the csv file.
Walter Roberson
Walter Roberson 2022 年 8 月 19 日
移動済み: Voss 2022 年 8 月 19 日
Please attach a short extract of the file, including any headers that are present.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 8 月 17 日

移動済み:

2022 年 8 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by