compress string of characters

조회 수: 10 (최근 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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by