checking character by for loop

5 ビュー (過去 30 日間)
Ugur Sahin
Ugur Sahin 2020 年 4 月 15 日
編集済み: Walter Roberson 2022 年 8 月 17 日
Hi guys,
I want to do that;
script = 'hi I am jo*hn' or ' hi I am jo3hn' (for=5per group)
(I have done for perfect string without noncharecter but I have to write version of that non-charecter entried. Program has to stop for loop when program see noncharacter.)
output=
Hiiam
Jo---
text='hi I am jo*hn'
for control=1:length(text1)
if text1(control) == '[^a-z]'
text1=text1(1:(control-1));
end
end
You do not have to edit printing section. I need only restrict text1 until program see a noncharacter.
  5 件のコメント
Ugur Sahin
Ugur Sahin 2020 年 4 月 15 日
yes bu I do not have to use isempty i guess ?
Walter Roberson
Walter Roberson 2020 年 4 月 15 日
~ismember(text1(control), list_of_permitted_characters)

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

回答 (1 件)

Swaroopa
Swaroopa 2022 年 8 月 17 日
編集済み: Walter Roberson 2022 年 8 月 17 日
You can use isLetter(A) function in the MATLAB.
text1='hi I am jo*hn'
for control=1:length(text1)
if isletter(text1(control))==0
if text1(control)~=' '
text=text1(1:(control-1));
break;
end
end
end
text1=text
Refer to the below documentation for more information:
Hope this helps.

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by