Command save writes to a nonreadable text file
조회 수: 1 (최근 30일)
이전 댓글 표시
When I execute the below Script file
x = 2; y = x^5;
save result.txt y
and open result.txt in MATLAB, the text shown is not readable. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/785933/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/785933/image.jpeg)
What tpye of encoding is this? I know that when I add -ascii the text becomes readable, but I'm curious to learn the type of encoding above and why is it the default text file.
댓글 수: 0
답변 (1개)
Cris LaPierre
2021년 11월 1일
The save command as written is creating a mat file. To create a text file, use the '-ascii' flag.
x = 2;
y = x^5
save result.txt y -ascii
댓글 수: 1
Walter Roberson
2021년 11월 1일
To expand slightly:
save() does not examine the file extension to figure out whether binary or text form is desired. save() always writes in binary unless you specifically ask for text.
참고 항목
카테고리
Help Center 및 File 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!