how can i convert a file into a matrix?

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.

 채택된 답변

Friedrich
Friedrich 2013년 4월 19일
편집: Friedrich 2013년 4월 19일

0 개 추천

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)

댓글 수: 2

Tommaso Ruscica
Tommaso Ruscica 2013년 4월 19일
편집: Tommaso Ruscica 2013년 4월 19일
thanks for answer :) I have to do a network simulation with some nodes that do a particular function(its works with matrix).So i want convert a file,send the matrix in the network and decode the matrix to file.(sorry for my english i'm italian)
PS:i tried that you say but a file.txt was convert into a cell with string values and i want integer as bit because i'll send byte in the network.
Friedrich
Friedrich 2013년 4월 19일
You cann apply uint8(tmp) to get a vector with unsinged integer values. When you write it back either cast to char or use as format specifier *uint8 instead of *char

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by