trouble with plotting dates on x-axis
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm using the following code:
%Question 2
%First load data into script
date= brisbanecbdaq2010(:,1)
pollution= brisbanecbdaq2010(:,2)
plot(date,pollution)
when I run this it gives the following:
Error using tabular/plot
Too many input arguments.
The data I'm using is simply a column of dates in the form dd/mm/yyyy and the second column is just numeric values.
can someone please help.
Thanks
댓글 수: 0
답변 (1개)
Walter Roberson
2018년 8월 25일
You get that error message when you attempt to plot using a table() object with more than one parameter. If you were to reduce down to, for example, plot(date) where date is a table object, then you would get a more clear error message such as,
Error using tabular/plot (line 156)
There is no plot method for the 'table' class. Plot the variables in a table using dot or brace subscripting.
The problem you have is that you used () indexing to extract a column from a table() object, instead of using {} indexing:
date = YourTable{:,3};
pollution = YourTable{:,8};
whereas you would have had something like
date = YourTable(:,3);
pollution = YourTable(:,8);
I showed you the {} syntax in https://www.mathworks.com/matlabcentral/answers/415891-how-to-plot-date-and-time-data-on-the-same-axis?s_tid=prof_contriblnk#answer_333789 which you have not replied to.
댓글 수: 2
Walter Roberson
2018년 8월 25일
If you are using the same file format as before, then column 2 is not pollution levels, and is instead time of day. readtable is not automatically detecting that it is time of day and is instead importing it as a cell array of character vectors. When you then try to use that cell array of character vectors as an argument to plot(), plot cannot parse the input correctly as it tries to interpret the character vectors as options.
In your other question I showed retrieving column 3 and column 8. Column 3 is datetime and column 8 is ppm10 numeric readings.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!