1

I need your help again :). I'm trying to plot multiple lines for a very large dataset. To start easier, I divided the dataset to get a TABLE in Matlab that contains 6 columns, with the first column representing the date that I want on my x-axis. Now I want to plot the other columns (and in the original file are a lot more than 6 columns) on the y axis, using a for loop. I tried the following, with no success:

hold on
for i=2:1:6
  plot(Doldenstock(:,1), Doldenstock(:,i));
end
hold off

As I understand this, this code would do exactly what I want for columns 2,3,4,5,6. However, I always get the same error code:

Error using tabular/plot Too many input arguments.

Error in Plotting_bogeo (line 6) plot(Doldenstock(:,1), Doldenstock(:,i));

Now, I don't know if maybe for loops like this don't work for tabes but only for arrays?

Thanks for your help in advance!

Cheers, Tamara

1 Answer 1

2

The function plot(x) expect x to be a scalar, a vector, or a matrix. But in your case the input is a table, because accessing a table with parentheses return a table, which is not supported.

If you read the doc "how to access data in a table" you will figure out that you need to use curly brace {} to extract the raw data (in your case a 1D matrix).

So use:

plot(T{:,1},T{:,2})
Sign up to request clarification or add additional context in comments.

4 Comments

The error says Error using tabular/plot Too many input arguments. so it seems that plot is defined (overloaded) for the table class, but it only supports a single input argument. Unfortunately I couldn't find any documentation for the method online. Also, if you can extract the matrices in the array you can skip the for loop altogether by plotting the first column versus the rest of the columns in one call to plot.
From the plot error warning There is no plot method for the 'table' class. Plot the variables in a table using dot or brace subscripting.. But yes indeed plot(T{:,1},T{:,2:6}) will work, no for loop needed here.
Ah, interesting. For two or more input arguments we get the canned "too many input arguments" error, but for a single table argument we get the error you quoted. Only mildly confusing :)
Thank you so much!!! It worked :). Can't believe how much time I spent trying to figure this out..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.