"randi(100)" Outputting Characters Instead of Integers
조회 수: 1 (최근 30일)
이전 댓글 표시
In line 2 below, "randi(100)" is returning characters, including black spaces, instead of integers. What code is converting "randi(100)" to return characters above line XXX, and how can I change this code to return integers?
dstr=num2str(d);
name=strcat('d',dstr,'_',randi(100));
댓글 수: 4
per isakson
2015년 10월 18일
IMO: it's better to use sprintf
>> name = sprintf( 'd%s_%d', dstr, randi(100) )
name =
dhello_91
채택된 답변
the cyclist
2015년 10월 18일
편집: the cyclist
2015년 10월 18일
I think you might want
name=strcat('d',dstr,'_',num2str(randi(100)));
This will convert the number to its string equivalent, rather than the ASCII value corresponding to that value (which is what I assume is happening now).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!