Borrar filtros
Borrar filtros

Insert string into cell array beside data

9 visualizaciones (últimos 30 días)
HEEKWON LEE
HEEKWON LEE el 15 de Dic. de 2016
Editada: dpb el 16 de Dic. de 2016
I would like to insert string for indexing beside data currently i have just data [1;2;4;.....] but it has special position as own has so if i want to sort those easily, had better insert specific string in there. It has some rules, "R" 10times, then "C" 10times finally "L" also ten times... and repeat and repeat......
How can I insert specific repeated string(char)...

Respuestas (1)

dpb
dpb el 15 de Dic. de 2016
Editada: dpb el 16 de Dic. de 2016
You can build character string sequences by memory manipulation just the same as numeric ones:
>> c='RCL'; % the initial characters to replicate
>> N=10; % the replication count for each
>> c=reshape(repmat(c.',1,N).',1,[]) % a pattern of N of the substring
c =
RRRRRRRRRRCCCCCCCCCCLLLLLLLLLL
>>
Now just replicate that as needed and concatenate with the rest into a cell array.
M=3; % say, whatever is multiplier need for final length
c=repmat(c.',M,1);
ADDENDUM
For brevity of presentation I purposely left the above as a row vector; the conversion to cellstr array should be obvious but just to make sure...
>> c=cellstr(reshape(repmat(c.',1,N).',[],1));
>> whos c
Name Size Bytes Class Attributes
c 30x1 1860 cell
>>
Is the column cellstring array needed... NB: reordered the reshape to '[],1' so cellstr is working on a column character string array.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by