compress string of characters

5 views (last 30 days)
majed majed
majed majed on 15 Aug 2017
Answered: John D'Errico on 15 Aug 2017
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!

Answers (1)

John D'Errico
John D'Errico on 15 Aug 2017
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.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!