Cant join 2 tables with same headers. vertcat error
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Adam Danz
am 26 Jan. 2021
Bearbeitet: Adam Danz
am 28 Jan. 2021
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]
0 Kommentare
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!