How do I add space between strings when I am using randperm?
古いコメントを表示
Sorry, I'm not expert but I'm learning.
I've tried some answer regarding how to add space between strings, but it seems that these methods do not apply when using a random generation of string.
If I use matrix concatenation (horzcat): ['A', ' ', 'B'] it will generate the space randomly.
if I use STRCAT then it give me error 'index exceed size of matrix' whatever I do.
This is my code:
string = ['BCDFGHKJLMNPQRSTVWXYZ'];
numRands = length(string);
set_length = 5;
set_string = string( round(randperm(21,set_length))); %21 consonants
Thanks a lot in advance for any help you might provide!
2 件のコメント
Walter Roberson
2013 年 10 月 2 日
randperm(21, set_length) is going to produce a list of integers. There is no point in round()'ing the integers before using them as indices.
Elisa
2013 年 10 月 2 日
採用された回答
その他の回答 (1 件)
Sean de Wolski
2013 年 10 月 3 日
You could also do this with strjoin (13a or newer)
string = ['BCDFGHKJLMNPQRSTVWXYZ'];
numRands = length(string);
set_length = 5;
set_string = strjoin(cellstr(string(randperm(21,set_length)).').',' ');
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!