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

조회 수: 8 (최근 30일)
JFz
JFz 2015년 7월 10일
댓글: Peter Perkins 2015년 7월 16일
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

답변 (1개)

Rohit Kudva
Rohit Kudva 2015년 7월 15일
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
Peter Perkins
Peter Perkins 2015년 7월 16일
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.

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

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by