Reputation: 15
I am trying to convert a cell array to a table so that it retains the header of the table. How can I do that in Matlab? I tried using cell2table, it works, but adds additional header.
my cell array:
txt: 3x2
'type' 'no'
'A' '1'
'B' '2'
When I use cell2table(txt), I get
txt1 txt2
_____________ ____
'type' 'no'
'A' '1'
'B' '2'
but I expect
type no
_____________ ____
'A' '1'
'B' '2'
Can anyone please suggest how to get this?
Upvotes: 1
Views: 793
Reputation: 19689
Specify the headers using the 'VariableNames'
property.
>> cell2table(txt(2:end,:),'VariableNames',txt(1,:))
ans =
2×2 table
type no
____ ___
'A' '1'
'B' '2'
Upvotes: 2