How to save a structure file into a text file

42 ビュー (過去 30 日間)
Suman Chatterjee
Suman Chatterjee 2020 年 12 月 8 日
回答済み: Monisha Nalluru 2020 年 12 月 11 日
I have a struct file with 3 fields(x,y and z) . Each field has many data points. I want to save them to a text file like
(x1 ,y1, z1)
(x2, y2, z2)
.................
Like this.
Plese help me on how can i save them into a text file.
  1 件のコメント
Rik
Rik 2020 年 12 月 8 日
This question sounds like the solution would be the top hit on Google. What did you try?

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

採用された回答

Monisha Nalluru
Monisha Nalluru 2020 年 12 月 11 日
From my understanding, you want to save txt file with data points
As an example
s=struct('x',[1,2,3],'y',[4,5,6],'z',[7,8,9]); % structure
fid=fopen('new.txt','w'); % create txt file
for i=1:length(s.x)
fprintf(fid,'(%f,%f,%f)\n',s.x(i),s.y(i),s.z(i)); % write data file in required format
end
fid=fclose(fid); % close the file
type new.txt % display the txt in file

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by