StackedPlot with two tables with specific variables

8 vues (au cours des 30 derniers jours)
Bhargav
Bhargav le 9 Fév 2024
Commenté : Bhargav le 9 Fév 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

Réponse acceptée

Cris LaPierre
Cris LaPierre le 9 Fév 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 commentaires
Cris LaPierre
Cris LaPierre le 9 Fév 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
Bhargav le 9 Fév 2024
ah I see. I think I have one shared variable hence it was giving me a duplicated error

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by