Effacer les filtres
Effacer les filtres

Insert string into cell array beside data

9 vues (au cours des 30 derniers jours)
HEEKWON LEE
HEEKWON LEE le 15 Déc 2016
Modifié(e) : dpb le 16 Déc 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)...

Réponses (1)

dpb
dpb le 15 Déc 2016
Modifié(e) : dpb le 16 Déc 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.

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