how to convert output to integer?
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2015-10-4
What is the difference between this question and your earlier http://uk.mathworks.com/matlabcentral/answers/246658-how-to-convert-output-to-integer ?
回答(1 个)
Stephen23
2015-10-4
编辑:Stephen23
2015-10-4
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:
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!