How to get rid of a warning when adding a new column to a table?

4 views (last 30 days)
I got the following warning when assigning a value to one cell in a table:
My table volTbl orignally had 4 columns, now I add one more column "Variance", then assign a value into that one cell:
volTbl.Variance = []
volTbl.Variance{1} = v
Then I got this:
Warning: The new variables being added to the table have fewer rows than the table. They have been extended with rows containing default values. > In table.subsasgnDot at 267 In table.subsasgn at 67
Could someone tell me what could be wrong?
Thanks a lot.
Jen

Answers (1)

Rohit Kudva
Rohit Kudva on 15 Jul 2015
Hi Jennifer,
I understand that you want to get rid of the warning message that you see on the command window when you add a value to a new column in your existing table.
Following is an example on how to avoid the warning:
% Assuming that table 'volTbl' exists in the workspace with a column 'Variance'
>> volTbl.Variance = [];
% In case 'v' is a scalar value, use the syntax 'table.ColumnName{rowNumber, colNumber} = value' to assign the value of 'v' into a cell in the 'Variance' column of the table.
>> volTbl.Variance{1,1} = v;
% In case 'v' is a matrix, use the syntax 'table.ColumnName = v' where v is a cell matrix whose number of rows is equal to the number of rows in the table.
volTbl.Variance = v;
Refer to the following link to check out other ways for adding/deleting columns in your table.
I hope this helps
-Rohit
  1 Comment
Peter Perkins
Peter Perkins on 16 Jul 2015
To follow up on what Rohit has said ...
You don't say what v is, or what your intended result is. It may be that v is an Nx1 cell array, and that's what you want to become the Variance variable in your volTbl table.
Your first assignment, deletes an existing variable Variance from the table. If you then (as Rohit says) simple assign
volHdr.Variance = v
you'd get the new variable. In fact, you don't even have to delete the old one, the assignment above will overwrite it.
You're getting a warning because you're assigning v into one element of what has to be an Nx1 column, where N is the height of volHdr. It may be that you intend to do that, but the warning is simply telling you, "Hey! I had to create a bunch of default values to fill in the other N-1 elements." One way to avoid that is to create the default values explicitly:
volHdr.Variance = cell(N,1)
volHdr.Variance{1} = v
Which of the above two strategies you want to take depends on what you intended to begin with.

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!