Adding a Column to a Table
Hello everyone, I’ve just started out with Matlab for uni and am trying to add a column to a table. I ran into the following error message
Error using .
To assign to or create a variable in a table, the number of rows must match the height of the table.
My code is written below:
%Creates a table called ‘tab’ using the data in the coronavirus-cases.csv
%file.
tab = readtable("coronavirus-cases.csv");
%Creates a row of zeros with the same height as tab.
newTabCol = zeros(height(tab), 1);
%Adds the column and titles it "Seven Day Average".
tab.newTabCol = "Seven Day Average";
What confuses me is that the height of newTabCol matches tab. Both have 153772 rows:
I’m sure I’m missing something basic but any help would be appreciated.
Kind regards,
JohnHello everyone, I’ve just started out with Matlab for uni and am trying to add a column to a table. I ran into the following error message
Error using .
To assign to or create a variable in a table, the number of rows must match the height of the table.
My code is written below:
%Creates a table called ‘tab’ using the data in the coronavirus-cases.csv
%file.
tab = readtable("coronavirus-cases.csv");
%Creates a row of zeros with the same height as tab.
newTabCol = zeros(height(tab), 1);
%Adds the column and titles it "Seven Day Average".
tab.newTabCol = "Seven Day Average";
What confuses me is that the height of newTabCol matches tab. Both have 153772 rows:
I’m sure I’m missing something basic but any help would be appreciated.
Kind regards,
John Hello everyone, I’ve just started out with Matlab for uni and am trying to add a column to a table. I ran into the following error message
Error using .
To assign to or create a variable in a table, the number of rows must match the height of the table.
My code is written below:
%Creates a table called ‘tab’ using the data in the coronavirus-cases.csv
%file.
tab = readtable("coronavirus-cases.csv");
%Creates a row of zeros with the same height as tab.
newTabCol = zeros(height(tab), 1);
%Adds the column and titles it "Seven Day Average".
tab.newTabCol = "Seven Day Average";
What confuses me is that the height of newTabCol matches tab. Both have 153772 rows:
I’m sure I’m missing something basic but any help would be appreciated.
Kind regards,
John table, column, add, add column, height, zeros MATLAB Answers — New Questions