Error message when attempting to plot selected area from a XLSX file: " Specify one or two table subscripts after the table."

Hi, I try to plot a defined area of data in an XLSX file, the area is defined from by the columns C11-C6796 and D11-D6796
So I define the upper left corner by C11 and the lower right corner by D6796. Which I then want to plot, but with
T=readtable('tempDataTrollhFlygpl.xlsx',Range="C11:D6796",ReadVariableNames=false);
plot(T)
xlabel('Year');
ylabel('Temperature');
I get
"Error using plot
Invalid number of input arguments. Specify one or two table subscripts after the table.
Error in uppgift32 (line 2)"
So the error is in the T part of the plot command? I used the MATLAB documentation to define the specific area of data to go in a 2D plot, but why does not that work?
Thanks

 Accepted Answer

What variables in T do you wnat to plot? Since T is a table, you must use one of these syntaxes

4 Comments

The variables (independent and dependent) are given in the columns of C and D.
C, which is the xvar: is C11-C6796
D, which is the yvar, is D11-D6796
I tried:
T=readtable('tempDataTrollhFlygpl.xlsx',Range="C11:D6796",preserve=true)
plot(T,Var2)
xlabel('Year');
ylabel('Temperature');
Unrecognized function or variable 'Var2'.
Error in uppgift32 (line 2)
plot(T,Var2)
But it is MATLAB that calls it "Var2"
T=readtable('tempDataTrollhFlygpl.xlsx',Range="C11:D6796",ReadVariableNames=false)
T = 6786×2 table
Var1 Var2 ___________ ________ 01-Jan-1961 {'0.1' } 02-Jan-1961 {'0.7' } 03-Jan-1961 {'1.0' } 04-Jan-1961 {'0.4' } 05-Jan-1961 {'0.0' } 06-Jan-1961 {'0.2' } 07-Jan-1961 {'0.0' } 08-Jan-1961 {'-1.1'} 09-Jan-1961 {'-1.1'} 10-Jan-1961 {'-0.8'} 11-Jan-1961 {'-5.4'} 12-Jan-1961 {'-6.8'} 13-Jan-1961 {'2.6' } 14-Jan-1961 {'0.3' } 15-Jan-1961 {'2.5' } 16-Jan-1961 {'-2.7'}
plot(T.Var1,str2double(T.Var2))
xlabel('Year');
ylabel('Temperature');
Your data is being read in as text. Here's another option that demontrates the table syntax.
T=readtable('tempDataTrollhFlygpl.xlsx',Range="C11:D6796",ReadVariableNames=false,TextType="string");
T = convertvars(T,"Var2","double")
T = 6786×2 table
Var1 Var2 ___________ ____ 01-Jan-1961 0.1 02-Jan-1961 0.7 03-Jan-1961 1 04-Jan-1961 0.4 05-Jan-1961 0 06-Jan-1961 0.2 07-Jan-1961 0 08-Jan-1961 -1.1 09-Jan-1961 -1.1 10-Jan-1961 -0.8 11-Jan-1961 -5.4 12-Jan-1961 -6.8 13-Jan-1961 2.6 14-Jan-1961 0.3 15-Jan-1961 2.5 16-Jan-1961 -2.7
plot(T,"Var1","Var2")
xlabel('Year');
ylabel('Temperature');

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2023b

Community Treasure Hunt

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

Start Hunting!