필터 지우기
필터 지우기

Recovering String Parts from combined string

조회 수: 2 (최근 30일)
v k
v k 2020년 11월 5일
댓글: Ameer Hamza 2020년 11월 5일
Hello,
If the two strings
k1='ab';
and
k2='c';
are concatenated as
k3=strcat(k1,k2);
then how can we recover the string k1 in its entirety from k3? It gives
k3(1)='a'
What can be done to get
k3(1)='ab'
and not k3(1)='a'.
That is, k3(1) should be equal to k1, and not the first part of k1.
Thanks.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 5일
This is not possible with simple arrays. You need to use cell arrays for this. For example
k1='ab';
k2='c';
k3 = {k1, k2};
Access them like this
>> k3{1}
ans =
'ab'
>> k3{2}
ans =
'c'
  댓글 수: 2
v k
v k 2020년 11월 5일
Thanks. That will do.
Ameer Hamza
Ameer Hamza 2020년 11월 5일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by