필터 지우기
필터 지우기

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

조회 수: 5 (최근 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에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by