MATLAB: How can i convert a file into a matrix

MATLAB

I want convert a file(.pdf/.txt/.jpg…) into matrix(with values integer or binary), and after i must ri-convert it. Can i do it?
PS:i tried only with images.jpg using imread() and imwrite(), but if i don't know the file extension? i want to do this also i don't know the nature of file.
thanks.

Best Answer

Hi,
you can always apply fileread to any file (and write it back with fopen,fwrite,flcose) but the main question will be: What do you want to do with the data you read into MATLAB?
tmp = fileread(FILENAME)
fid = fopen(OUTPUT_FILENAME,'w')
fwrite(fid,tmp,'*char')
fclose(fid)