Right hand side of an assignment into a table must be another table or a cell array.
70 次查看(过去 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
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:
采纳的回答
更多回答(2 个)
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)
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!