Azzera filtri
Azzera filtri

Insert string into cell array beside data

9 visualizzazioni (ultimi 30 giorni)
HEEKWON LEE
HEEKWON LEE il 15 Dic 2016
Modificato: dpb il 16 Dic 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)...

Risposte (1)

dpb
dpb il 15 Dic 2016
Modificato: dpb il 16 Dic 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.

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by