How can I write an array to a txt file such that it looks like MATLAB syntax

조회 수: 1 (최근 30일)
If I have an array, for example
A = [1 2 3 4;
-1 0 1 2;
3 9 5 7;
12 100 1000 1012];
How can I write this to a text file such that when I do, it will look the same as what I wrote to declare A? In otherwords I want the txt file to contain
A = [1 2 3 4;
-1 0 1 2;
3 9 5 7;
12 100 1000 1012];

채택된 답변

Fangjun Jiang
Fangjun Jiang 2023년 4월 25일
use mat2str(), write the string to the text file
A = [1 2 3 4;
-1 0 1 2;
3 9 5 7;
12 100 1000 1012];
str=mat2str(A)
str = '[1 2 3 4;-1 0 1 2;3 9 5 7;12 100 1000 1012]'
eval(str)
ans = 4×4
1 2 3 4 -1 0 1 2 3 9 5 7 12 100 1000 1012

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by