Stackedplot with x-axis vector

Hello,
I am very new and am struggling to get stackedplot to work at all.
I would like to use stackedplot to create some stacked line curves with a common x-axis. The x-axis should be wavelength values that I have as a column in my spreadsheet ('Channels'). The two line graphs should be intensity values of 'illite' and 'kaolinite', also listed in columns.
This is the code I have (with spreadsheet specifications removed):
close all
figure
tbl = readtable('___','Sheet','___');
head(tbl,2);
stackedplot({'Channel'},{'illite','kaolinite'});
I get the error:
Error using stackedplot (line 76)
Expected x to be one of these types:
datetime, duration, double, single, uint8, uint16,
uint32, uint64, int8, int16, int32, int64, logical
Error in stackedplottest (line 14)
stackedplot({'Channel'},{'illite','kaolinite'});
Please help :(

Respuestas (1)

Steven Lord
Steven Lord el 24 de Feb. de 2020
Where is the data from which you want to create the stackedplot stored?
stackedplot({'Channel'},{'illite','kaolinite'});
I think you want to create the stackedplot from the variable Channel in the table array tbl. But where have you told stackedplot to use the data from the variable tbl?

4 comentarios

Erin Gibbons
Erin Gibbons el 24 de Feb. de 2020
It's in a spreadsheet.
I copied the sheet and attached it to my original question so you can look at how the data is stored. As far as I can tell all my variable are numbers, so I don't know what's going wrong.
My code seems to read the table just fine (the "head(tbl,2);" call works)
Steven Lord
Steven Lord el 24 de Feb. de 2020
The first input to the stackedplot function is supposed to be the table that contains the data you want to use to create the stacked plot. You accidentally omitted that input. Pass tbl as the first input, {'Channel'} as the second, etc.
Erin Gibbons
Erin Gibbons el 24 de Feb. de 2020
But if I do that stackedplot has too many input arguments, right?
The plot works if I use:
stackedplot(tbl,{'illite','kaolinite'});
but the x-axis is just the row numbers, and I need it to be the wve channels listed in 'channel'.
I tried your suggestion and go the following error:
>> stackedplottest
Error using colstyle
Requires a string scalar or a character vector
argument.
Error in stackedplot>parseTableInputs (line 170)
[l,c,m,tmsg] = colstyle(args{args2delete+1});
Error in stackedplot (line 71)
[extraArgs, args] = parseTableInputs(args);
Error in stackedplottest (line 14)
stackedplot(tbl,{'Channel'},{'illite','kaolinite'});
Steven Lord
Steven Lord el 24 de Feb. de 2020
Okay. I didn't read the documentation quite as thoroughly as I should have. Using one of the sample table arrays from the stackedplot documentation:
tbl = readtable('outages.csv');
I want to plot two of the variables, Loss and Customers, and I want to use the OutageTime as the X axis.
stackedplot(tbl, {'Loss', 'Customers'}, 'XVariable', 'OutageTime')
So I believe what you want is:
stackedplot(tbl, {'illite', 'kaolinite'}, 'XVariable', 'Channel')

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Feb. de 2020

Comentada:

el 24 de Feb. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by