Clear Filters
Clear Filters

trouble with plotting dates on x-axis

1 view (last 30 days)
Noah Poole
Noah Poole on 25 Aug 2018
Commented: Walter Roberson on 25 Aug 2018
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

Answers (1)

Walter Roberson
Walter Roberson on 25 Aug 2018
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);
  2 Comments
Noah Poole
Noah Poole on 25 Aug 2018
Edited: Walter Roberson on 25 Aug 2018
Hi,
when I use this now I get:
date2016 = Brisbane2016{:,1};
pollution2016 = Brisbane2016{:,2};
plot(date2016,pollution2016)
which returns:
Error using plot
Not enough input arguments.
Walter Roberson
Walter Roberson on 25 Aug 2018
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.

Sign in to comment.

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!