StackedPlot with two tables with specific variables

조회 수: 4 (최근 30일)
Bhargav
Bhargav 2024년 2월 9일
댓글: Bhargav 2024년 2월 9일
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

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 2월 9일
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
Cris LaPierre
Cris LaPierre 2024년 2월 9일
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 2024년 2월 9일
ah I see. I think I have one shared variable hence it was giving me a duplicated error

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by