How do I convert a character array A(N,1) to a string array B(N,12)?

조회 수: 5 (최근 30일)
Example:
entry
A(1,1) = 'US5525411048'
I've tried every function I could find. Also fn string is being phased out and fn compose doesn't exist. Thanks
isin1 = string(rawb(:,6));
isin1 = [rawb(:,6)];
isin2= cellstr(rawb(:,6));
isinc = strrep(isin_char,' ',''',''');
isinc = strfind(rawb(:,6),',');
isinc = str(rawb(:,6),3:11);
isinc12 = compose('%12s',rawb(:,6)); % no compose function
isinc12 = reshape(rawb(:,6),[size(rawb(:,6),1),12])
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 4월 2일
compose() requires R2016b or later; perhaps you are using an earlier version?

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 4월 2일
A = "US5525411048";
B = char(A);

추가 답변 (1개)

dpb
dpb 2017년 4월 2일
편집: dpb 2017년 4월 2일
Don't have string in R2014b so can only read documentation, and your posting isn't anything anybody can actually test as written (but the crystal ball just got out of the shop yesterday and seems to be functional) so I'll guess that the
A(1,1) = 'US5525411048'
wasn't really meant as an assignment statement but the result of displaying A(1,1). If that is so, the single ticks around the string of characters implies it is a cellstr not character string and
s=string(A);
should work just fine. The other examples are too lacking in information about what rawb is to be able to do much (as in anything) regarding them.
I see nothing in current documentation about "fn string ... being phased out". There's a comment that as of latest release you can use double quotes instead of string for conversion to character data to string as a shorthand convenient notation, but that doesn't imply the function is in any way deprecated; it's just noting one place in which there's a more convenient syntax.
  댓글 수: 1
Nancy Hammond
Nancy Hammond 2017년 4월 2일
When I used string function, my 2015 version gives an error 'string ... being phased out'. Fortunately char(txt) rather than char(raw), the 2nd and 3rd output arguments of xlsread worked

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

카테고리

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