フィルターのクリア

Cant join 2 tables with same headers. vertcat error

9 ビュー (過去 30 日間)
Sergio Huerta
Sergio Huerta 2021 年 1 月 25 日
編集済み: Adam Danz 2021 年 1 月 28 日
Can someone explain why im getting this error? Im trying to join the rows of 2 tables who have the exact same headers, but im getting an error? Online says that vertcat or [T1;T2] should do the trick no problem, but this is not the case for me. Please help
a =
struct with fields:
id: 'a'
mode: 'read'
name: 'firstname'
type: 'double'
>> b = a
b =
struct with fields:
id: 'a'
mode: 'read'
name: 'firstname'
type: 'double'
>> b.name = 'differentfirstname'
b =
struct with fields:
id: 'a'
mode: 'read'
name: 'differentfirstname'
type: 'double'
>> Ta = struct2table(a)
>> Tb = struct2table(b)
>> [Ta;Tb]
An error occurred when concatenating the table variable 'name'
using VERTCAT.
Caused by:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.

回答 (1 件)

Adam Danz
Adam Danz 2021 年 1 月 26 日
編集済み: Adam Danz 2021 年 1 月 28 日
The error is because of a difference in character length of the two "name" fields. Vertical concatenation of characters into a character array requires the same number of characters, even in a table.
Use a cell array of characters, a string (shown below), or a category instead.
a = struct('id','a','mode','read','name',"firstname",'type','double');
% string ^ ^
b = a;
b.name = "differentfirstname"; % string, not char-vector
Ta = struct2table(a);
Tb = struct2table(b);
[Ta;Tb]
ans = 2x4 table
id mode name type __ ____ ____________________ ______ a read "firstname" double a read "differentfirstname" double

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by