# StackedPlot with two tables with specific variables

7 visualizzazioni (ultimi 30 giorni)
Bhargav il 9 Feb 2024
Commentato: Bhargav il 9 Feb 2024
I have two tables say table A and table B. A and B has different number of variables but the same number of rows.
following the syntax of stackedplot if I want to do a stackedplot for A
I would write something like this stackedplot(A,[''variable name 1''," [variable name 2']")
My question:
I want to have stacked plot of two tables A and B but specific variables from table A and specific variables from table B
stackedplot(A,["variable1ofA","var2ofA", "var3ofA"],B,["var1ofB","var2ofB"])
The syntax for multiple table is stackedplot(tbl1,tabl2) how do I specify which variables of each table ?
How can I achieve this ?
Thank you
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Cris LaPierre il 9 Feb 2024
If they have the same number of rows, I think what you would want to do is
T = [A(:,["variable1ofA","var2ofA", "var3ofA"]),B(:,["var1ofB","var2ofB"])]
stackedplot(T)
If the tables do not share the same variable names, this may work as well (untested)
stackedplot([A,B],["variable1ofA","var2ofA", "var3ofA","var1ofB","var2ofB"])
##### 6 CommentiMostra 4 commenti meno recentiNascondi 4 commenti meno recenti
Cris LaPierre il 9 Feb 2024
The 2nd syntax should work. I did have to make sure there are no shared variable names between the 2 tables, and that both tables have the same number of rows. Here's a working example.
x = (0:0.1:25).';
TA = array2table([x sin((1:4).*2.*pi.*x/25)]);
TB = array2table([x sin((5:8).*2.*pi.*x/25)]);
TB.Properties.VariableNames = ["X","Y1","Y2","Y3","Y4"];
stackedplot([TA,TB],["Var2","Var3", "Var4","Y1","Y2"])
Bhargav il 9 Feb 2024
ah I see. I think I have one shared variable hence it was giving me a duplicated error

Accedi per commentare.

### Categorie

Scopri di più su Line Plots in Help Center e File Exchange

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by