How can i convert my array into different string cells Array=[0, 1,3,0] I used Cells=cellstr(num2str(array) ) And i got 1×1 cell {'0 1 3 0' } I want my cell to be 1×4(or 1×any number) {'0','1','3','0'} Please help

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 1월 8일

2 개 추천

This creates a 1x4 cell array
Array = [0, 1,3,0];
A = num2cell(Array);
C = cellfun(@num2str,A,'UniformOutput',false)
C = 1x4 cell array
{'0'} {'1'} {'3'} {'0'}

댓글 수: 3

Cris LaPierre
Cris LaPierre 2021년 1월 8일
Would definitely recommend using actual string array instead, though.
Ayman Abdalla
Ayman Abdalla 2021년 1월 8일
Its working Thank you very much 🙏
Ayman Abdalla
Ayman Abdalla 2021년 1월 8일
Noted thank you

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

추가 답변 (1개)

Steven Lord
Steven Lord 2021년 1월 8일

1 개 추천

Rather than creating a cell array containing char vectors, why not create a string array?
x = [0 1 3 0];
s = string(x)
s = 1×4 string array
"0" "1" "3" "0"
three = s(3)
three = "3"
threeChar = s{3}
threeChar = '3'
whos
Name Size Bytes Class Attributes s 1x4 312 string three 1x1 150 string threeChar 1x1 2 char x 1x4 32 double
I'm not 100% sure that indexing with curly braces to create a char vector was supported in release R2018b but if it wasn't calling char on the string array would work.

카테고리

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

제품

릴리스

R2018b

질문:

2021년 1월 8일

댓글:

2021년 1월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by