简体   繁体   中英

write matrix to one column of a table - matlab

>> x = 'x';
>> y = [1,2,3,4];
>> T = table({x},{y});
>> writetable(T,'T.txt','Delimiter','\t')

when I open T.txt the different elements of y are written in separate columns:

Var1    Var2_1  Var2_2  Var2_3  Var2_4
x          1       2       3      4

is there a way to put them in one single column? eg:

Var1  Var2
x     [1,2,3,4]

For creating that table, you can make Var2 a character array instead. Now if you write that table, you will get your expected result.

T = table({x}, mat2str(y));
writetable(T,'T.txt','Delimiter','\t');

Result:

Var1    Var2
x   [1 2 3 4]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM