deleting part of chars

5 ビュー (過去 30 日間)
Kangkeon Jeon
Kangkeon Jeon 2019 年 11 月 6 日
コメント済み: Walter Roberson 2019 年 11 月 6 日
So I have a char like 'FSAJFALSFJSCXKHZVUIAHFKFSDVXCNMVBMAEHFSADFDSASADFHDSUIVCX'
and i need to delete one random length of char longer than 10 that's outside of first 10 and last 10. i have to repeat this 10 times so i have 10 char that has random length deleted as long as it's within the limited range (outside first 10 and last 10).
for example, if my char has 100 characters, it might delete 11~60 or 43~54 or 50~68. but not 9~44 or 77~95 because these are within first 10 or last 10. how can i accomplish this?

採用された回答

Akira Agata
Akira Agata 2019 年 11 月 6 日
Like this?
% Random string with 100 A-Z characters
str = char(randi([65 90],1,100));
% Start position (random number between 11 and 80)
pt1 = randi([11 80],1);
% End position (random number between pt1+9 and 89)
pt2 = randi([pt1+9 89],1);
% Delete characters between pt1 and pt2
str(pt1:pt2) = [];
  2 件のコメント
Kangkeon Jeon
Kangkeon Jeon 2019 年 11 月 6 日
編集済み: Kangkeon Jeon 2019 年 11 月 6 日
how would i change it so that it applies to char with any length but not just 100 characters (still with outside first 10 and last 10 limit)?
Walter Roberson
Walter Roberson 2019 年 11 月 6 日
N = 123; %or as needed
W = 10; %how many to delete
str = char(randi([65 90],1,N)); %A to Z
pt1 = randi([W+1 N-2*W+1],1);
pt2 = randi([pt1+W-1, N-W],1);
str(pt1:pt2) = [];

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by