Replace character vector in Matlab table with another character vector of different size?
3 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 9 Sep 2017
['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 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!