problem in converting double Array into character?

There is an Array with double type and I want to convert it into character but there is a problem and that is the number of each cell contains the number of character. for example I need to convert 49 to 1 in character. i write the code below but it doesn’t work at all.it just to show you what I mean. Value of a Array is:
a(1)=49
a(2)=49
a(3)=52
a(4)=50
%code
z(1)=num2str(a(1));
z(2)=num2str(a(2));
z(3)=int2str(a(3));
numberplate = char(str2num(z(1)))+char(str2num(z(2)))+char(str2num(z(3))+ char(str2num(z(4))
%end of code
And the value of numberplate should be numberplate==’1132’. thanks

 채택된 답변

Cedric
Cedric 2013년 10월 26일
편집: Cedric 2013년 10월 26일
Just "type cast" to char:
>> numberplate = char(a)
numberplate =
1132
In your code, you convert to string, then to numeric again, then you "type cast". You can go directly for the latter.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 26일
You should use cell array
clear
a(1)=49
a(2)=49
a(3)=152
a(4)=50
z{1}=num2str(a(1));
z{2}=num2str(a(2));
z{3}=int2str(a(3));
z{4}=int2str(a(4));
numberplate = char(str2num(z{1}))+char(str2num(z{2}))+char(str2num(z{3}))+ char(str2num(z{4}))

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2013년 10월 26일

편집:

2013년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by