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!!!
0 个评论
回答(2 个)
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,:)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!