Replace character vector in Matlab table with another character vector of different size?

3 次查看(过去 30 天)
Hi,
I'm trying to replace the contents of a cell in a matlab table which is either empty or has a character vector, with another character vector which has a different size. Any ideas how to do this? Here's the example and error I get:
T = table(['Gene1';'Gene2'],'VariableNames',{'Gene'});
R = table(['Tnfrsf12'; 'HIF1aITG'],'VariableNames',{'Gene'});
If I use the following:
T.Gene(1,:) = R.Gene(1,:);
I get this error:
Subscript assignment dimension mismatch
If I use the following script:
T.Gene(1) = R.Gene(1);
It will only replace the first letter of R.Gene(1) with the first letter of T.Gene(1)
How do I get it to replace the entire thing?
Thanks much in advance!!!

回答(2 个)

Jose Marques
Jose Marques 2017-9-9
Maybe you can use structs instead of tables.

Walter Roberson
Walter Roberson 2017-9-9
['Gene1';'Gene2'] forms a char array. Like numeric arrays, char arrays have a fixed number of rows and columns, and you cannot make one entry longer without making the other entries longer as well.
I recommend switching to cell array of char vector
T.Gene = cellstr(T.Gene);
T.Gene{1} = R.Gene(1,:)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by