필터 지우기
필터 지우기

Question about outputting a matrix to a pgm file

조회 수: 2 (최근 30일)
Botong Zhu
Botong Zhu 2024년 2월 2일
댓글: Walter Roberson 2024년 2월 2일
Hello, I'm new to matlab and I've got a question about outputting matrix to a pgm file. I know the most direct way of doing this is using imwrite function, but I want to ask if there's any other method or code that could output the matrix to pgm file without using imwrite function, for example, using functions like fwrite? Please let me know if there's any idea.

답변 (1개)

Walter Roberson
Walter Roberson 2024년 2월 2일
Yes, the PGM file format is relatively simple. You can fopen(), fprintf() several times, and fclose()
It is not clear why you would want to do this yourself, but...
Note: if you are writing uint16 data, then the most significant byte must be first -- corresponding to fopen() with 'ieee-be' option.
  댓글 수: 2
Botong Zhu
Botong Zhu 2024년 2월 2일
So basically I just need to print all these necessary information(magic number, width, height etc) to the pgm file I desired using fprintf() and then it's done, if I didn't miss anything?
Walter Roberson
Walter Roberson 2024년 2월 2일
Yes, fprintf() the header values.
You probably need to fwrite() the data

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

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by