compress string of characters

4 vues (au cours des 30 derniers jours)
majed majed
majed majed le 15 Août 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!

Réponses (1)

John D'Errico
John D'Errico le 15 Août 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.

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