compress string of characters

4 visualizzazioni (ultimi 30 giorni)
majed majed
majed majed il 15 Ago 2017
Risposto: John D'Errico il 15 Ago 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!

Risposte (1)

John D'Errico
John D'Errico il 15 Ago 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.

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by