hi
I have this string:
str = ["a" "b" "c"]
which gives:
"a" "b" "c"
how can I have this new string with the previouse one:
new_str = "a" "c"
in other words, I want to delete "b" completely.
I have tried erase but with that I will have:
"a" "" "c"
thanks in advance.

 채택된 답변

DGM
DGM 2022년 5월 21일

1 개 추천

How do you intend to identify the thing you want to delete? Do you simply want to delete the second string in the array?
str = ["a" "b" "c"];
str(2) = []
str = 1×2 string array
"a" "c"
Or do you want to delete all (or the first) instance of the string "b" in the array?
str = ["a" "b" "c"];
idx = strcmp(str,"b");
str(idx) = []
str = 1×2 string array
"a" "c"

댓글 수: 2

Mahdi Hayati
Mahdi Hayati 2022년 5월 21일
Thank you DGM for both.
or
str = ["a" "b" "c"];
str(str=="b") = []
str = 1×2 string array
"a" "c"

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

ajay kumar
ajay kumar 2022년 7월 6일

0 개 추천

str = ["a" "b" "c"];
y= find(contains(str,"b"))
y = 2
str(y) = []
str = 1×2 string array
"a" "c"

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2022년 5월 21일

답변:

2022년 7월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by