compress string of characters

4 ビュー (過去 30 日間)
majed majed
majed majed 2017 年 8 月 15 日
回答済み: John D'Errico 2017 年 8 月 15 日
suppose that I have a string of characters of length n, how can I compress it to be of the length l, where l<n by omitting randomly some of its middle characters. note that the first and last m character (where m<5)should not be omitted. any answer will be appreciated. thank you!

回答 (1 件)

John D'Errico
John D'Errico 2017 年 8 月 15 日
Note that variable l (lower case L) is a really bad variable to use. BAD IDEA, since there is very little to distinguish between l and the number 1. In the font used as I am typing, the two are almost indistinguishable. (For some reason, they change the font when the text of an answer is displayed. Why does that seem silly to me?)
Surely you can select n-L random INTEGERS, all of which lie between 2 and n-1. Do so without replacement, so randperm is appropriate.
help randperm
Then just delete the comparable elements from the string vector.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by