Easiest way to load structure array from a text file

5 ビュー (過去 30 日間)
Leos Pohl
Leos Pohl 2021 年 7 月 16 日
コメント済み: Leos Pohl 2021 年 7 月 16 日
I currently have a structure array defined in the code as:
C.a = "something";
C.b = 1;
% useful comment
C.c = [ 1.3, 2.0, 3.1];
I would like to create a text file that would contain the values so that i can compile the code and change the struct without recompilation. What is the easiest way to do this? ( I read about readstruct but that requires creating an xml file which is an overkill)
  2 件のコメント
Jan
Jan 2021 年 7 月 16 日
What is fixed? What is flexibel? Does the struct contain 3 fields in all cases?
Leos Pohl
Leos Pohl 2021 年 7 月 16 日
The number of fields is fixed. The values on the right hand side of the equal sign can change but always within the same type (column vector will be column vector, double will be double, string will be string etc.

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

回答 (1 件)

Scott MacKenzie
Scott MacKenzie 2021 年 7 月 16 日
編集済み: Scott MacKenzie 2021 年 7 月 16 日
To save the data in the structure C in a file...
save('savedata.mat', 'C');
To retrieve the data as a structure C later...
load('savedata.mat');
I'm assuming here that the key issue is storing the data in a file and retrieving the data later in the same format. Of course, a .mat file is not a text file.
  1 件のコメント
Leos Pohl
Leos Pohl 2021 年 7 月 16 日
Since this is for a compiled application, it would be better if the external file was a text file so that it can be adjusted without matlab itself.

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by