Effacer les filtres
Effacer les filtres

how to convert output to integer?

7 vues (au cours des 30 derniers jours)
fahim GH
fahim GH le 4 Oct 2015
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)

Réponses (1)

Stephen23
Stephen23 le 4 Oct 2015
Modifié(e) : Stephen23 le 4 Oct 2015
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:

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by