how to convert output to integer?

조회 수: 7 (최근 30일)
fahim GH
fahim GH 2015년 10월 4일
댓글: Walter Roberson 2015년 10월 4일
hi i wrote the following code for converting image to textfile but the arrays of output are hexadecimal in the textfile.how could I convert them to integer??? tnx
a= imread('D:\IP1\12.jpg');
I=rgb2gray(a);
b = I(:);
fid = fopen('D:\IP1\in2.txt');
fprintf(fid, '%x\n', b);
fclose(fid)

답변 (1개)

Stephen23
Stephen23 2015년 10월 4일
편집: Stephen23 2015년 10월 4일
The output values are hexadecimal because that is exactly what you are telling fprintf to write:
fprintf(fid, '%x\n', b);
where the format specifier '%x' exactly means hexademical. If you want another number format, then you need to read the fprintf documentation and pick a format specifier that suits your needs: there are many options, so it is worth reading the documentation carefully. You might like to start with %d:
fprintf(fid, '%d\n', b);
More details here:

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by