Right hand side of an assignment into a table must be another table or a cell array.

조회 수: 73 (최근 30일)
bias = table('Size',[1,11], 'VariableTypes', {'datetime', 'string', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'cell'}, 'VariableNames', ["time", "config", "ypos", "FA", "FN", "thrust", "CTA", "CTC", "VAB", "VBC", "pressure"]);
bias(1,4:10) = [1 2 3 4 5 6 7]; % throws error
bias(1,4) = 5; % Also throws error
both ways of assigning data into my table result in the error "Error using () Right hand side of an assignment into a table must be another table or a cell array."
The data type for these field is all double, why can I not assign a value with row/column indexing in this way? particularly the second one?
I can do
bias.FA = 1;
bias.FN = 2;
% etc...
but is there a way to fill these columns in one line? particularly.. to fill adjacent columns in a table using an array?
  댓글 수: 1
Stephen23
Stephen23 2023년 10월 27일
"The data type for these field is all double, why can I not assign a value with row/column indexing in this way?"
Because parentheses refers to the table array itself.
If you want to refer to the table content then use curly braces:

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

채택된 답변

Voss
Voss 2023년 10월 27일
bias{1,4:10} = [1,2,3,4,5,6,7];
bias{1,4} = 5;
  댓글 수: 2
cdlapoin
cdlapoin 2023년 10월 27일
Thank you, the error message had me convinced that the problem was on the right hand side of the assignment, so I had tried things like:
bias(1,4:10) = {1,2,3,4,5,6,7}
bias(1,4:10) = {[1,2,3,4,5,6,7]}
but I never tried curly brackets on the left side. The fact that
bias(1,4)
returns a Table datatype should have been a clue, but I still couldn't make the connection.

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

추가 답변 (2개)

KSSV
KSSV 2023년 10월 27일
편집: KSSV 2023년 10월 27일
bias = table('Size',[1,11], 'VariableTypes', {'datetime', 'string', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'cell'}, 'VariableNames', ["time", "config", "ypos", "FA", "FN", "thrust", "CTA", "CTC", "VAB", "VBC", "pressure"]);
val = 1:7 ;
for i = 1:7
bias.(i+3) = val(i) ;
end
OR
time = datetime ;
config = {'Missing'} ;
ypos = 0 ;
FA = 1 ;
FN = 2 ;
thrust = 3 ;
CTA = 4 ;
CTC = 5 ;
VAB = 6 ;
VBC = 7 ;
pressure = {100} ;
bias = table(time,config,ypos,FA,FN,thrust,CTA,CTC,VAB,VBC,pressure)

Walter Roberson
Walter Roberson 2023년 10월 27일
bias = table('Size',[1,11], 'VariableTypes', {'datetime', 'string', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'double', 'cell'}, 'VariableNames', ["time", "config", "ypos", "FA", "FN", "thrust", "CTA", "CTC", "VAB", "VBC", "pressure"]);
%version 1
bias(1,4:10) = num2cell([1 2 3 4 5 6 7]);
bias(1,4) = {5};
%version 2
bias{1,4:10} = [1 2 3 4 5 6 7];
bias{1,4} = 5;
bias
bias = 1×11 table
time config ypos FA FN thrust CTA CTC VAB VBC pressure ____ _________ ____ __ __ ______ ___ ___ ___ ___ ____________ NaT <missing> 0 5 2 3 4 5 6 7 {0×0 double}

카테고리

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

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by