Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
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!!!

Réponses (2)

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

Walter Roberson
Walter Roberson le 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,:)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by