how to convert output to integer?

4 Ansichten (letzte 30 Tage)
fahim GH
fahim GH am 4 Okt. 2015
Kommentiert: Walter Roberson am 4 Okt. 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);
% iD conversion
b = I(:);
% New txt file creation
fid = fopen('D:\IP1\in2.txt');
% Hex value write to the txt file
fprintf(fid, '%x\n', b);
% Close the txt file
fclose(fid)

Antworten (1)

James Tursa
James Tursa am 4 Okt. 2015
Use %d instead of %x for the output format.
  2 Kommentare
fahim GH
fahim GH am 4 Okt. 2015
thanks for answering,i have this error now
Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
Error in imgtotxt (line 8) fprintf(fid, '%d\n', b);
Walter Roberson
Walter Roberson am 4 Okt. 2015
[fid, message] = fopen('D:\IP1\in2.txt', 'wt');
if fid < 0
error('Failed to open because: %s', message);
end

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by