Command save writes to a nonreadable text file

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.
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.

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 11 月 1 日

0 投票

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
You can read more and see an example here.

1 件のコメント

Walter Roberson
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeText Analytics Toolbox についてさらに検索

製品

リリース

R2021b

タグ

質問済み:

2021 年 11 月 1 日

コメント済み:

2021 年 11 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by