Why do I see an error when adding character data to a table?

7 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2018 年 6 月 14 日
回答済み: MathWorks Support Team 2018 年 6 月 20 日
I have a table like the following:
x=[1;2;3];
y=[4;5;6];
T=table(x,y)
Then I add a column of placeholder values:
z=zeros(3,1);
T=horzcat(T,table(z))
Now want to fill in the table with data from a serial port:
for i=1:3
T{i,'z'} = query(device,'command') % or: T(i,'z') = query(device,'command')
end
I get one of the following errors:
The value being assigned from must have 1 columns.
or
The number of table variables in an assignment must match.
How can I put this data in the table?

採用された回答

MathWorks Support Team
MathWorks Support Team 2018 年 6 月 14 日
You are seeing these errors because the value returned from the query function is a 1xN character vector, but the data in that spot of the table is a 1x1 double. The data in a column must all have the same type and size.
Instead, make this a column of strings. You can still create placeholder values and fill them in one by one.
z=strings(3,1);
T=horzcat(T,table(z))
for i=1:3
T{i,'z'} = string(query(device,'command'))
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by