MatLab won't allow me to label the columns in a table that I created

16 views (last 30 days)
Hello,
I am trying to create a very simple table via the following code:
Latency_Info = [124, 203, 301; 143, 201, 280]
Latency_Table = table(Latency_Info)
Latency_Table.Row = ["T7", "T8"]
Latency_Table.Variables = ["P1", "N1", "P2"]
I am able to add the row names via this code, however, when I try to lable the coloumns of the table, I get the following error:
"To assign to, or create a variable in a table, the number of rows must match the height of the table."
Could anyone point me in the right direction to address this issue

Accepted Answer

Star Strider
Star Strider on 10 Nov 2019
You are not creating your table correctly, and you are not using the correct syntax to set the row and column names.
Try this:
Latency_Info = [124, 203, 301; 143, 201, 280];
Latency_Table = array2table(Latency_Info);
Latency_Table.Properties.RowNames = ["T7", "T8"];
Latency_Table.Properties.VariableNames = ["P1", "N1", "P2"];
producing:
Latency_Table =
2×3 table
P1 N1 P2
___ ___ ___
T7 124 203 301
T8 143 201 280

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!