我使用 struct2table(select(...))
从 mySQL 导入数据。
不幸的是,数据是这样存储的:
A B
______________ ______________
[1x500 double] [1x500 dobule]
我想转置表格条目,使其看起来像这样:
A B
______________ ______________
[500x1 double] [500x1 double]
我需要更改它,因为我想添加 RowNames
并且它仅在转置条目时才有效。
我可以使用 transpose()
,但我必须多次这样做,而且我正在寻找将整个表格作为输入并以所需方式转置它的东西。
我尝试了 flip()
、rot90()
、table'
但都没有用。
也许有办法在导入过程中避免这个问题,但我不知道怎么做。非常感谢关于其中任何一个的提示。
1x5 样本如下所示:
area
______________________________________________
6.8452 5.3581 3.2842 60.0434 15.5756
(Columns 1 through 5)
inhabitants
_________________________________________________________________
11672 9136 5600 102379 26558 41437
(Columns 1 through 5)
最佳答案
为什么不循环?
newTable = table();
for ii = 1:size(oldTable,2)
newTable{:,ii} = oldTable{:,ii}.'; end
newTable.Properties.VariableNames = oldTable.Properties.VariableNames;
但是,正如您已经指出的那样,最好在导入过程中避免这个问题......以某种方式。
关于mysql - 转置从 mySQL 导入的表的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40633327/