File Exchange

image thumbnail


version (2.06 KB) by Ivar Eskerud Smith
Print a struct to file.


Updated 02 Mar 2012

View License

Print a struct to file. The output can be aligned to be more human-readable, or be separated by a specified delimiter.
Requires the getarg function.

struct2File( s, 'c:\file.txt', 'align', true, 'sort', false );

Cite As

Ivar Eskerud Smith (2021). struct2File (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

Ivar Eskerud Smith

Rob, that`s just the way it is. At the time I made this function (a long time ago) I did not know about the inputParser class. And many of my other submissions use the getarg function, so I added it as a separate submission.

Rob Campbell

Why not include getArg in this submission? Or, better yet, why not use MATLAB's inputParser class?

Ali Komai

Works great. Thank you!

Johann Walter

Really nice function !

Caution: Do not forget to download the "getarg" function from matlab file exchange website.

Sandra Gomes


this is great. you just saved me hours, thx.




It seems to do what it says. You'll need to download the other file:

I was hoping for something that would work recursively for structs. EG:
>> s1 = struct('one',1,'two','two');
>> s2 = struct('field1',1.1,'field2','a string!');
>> s.s1 = s1;
>> s.s2 = s2;
>> struct2File( s, 'C:/test.txt')

It doesn't do what I was hoping it would, but it still works for simple structs.

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!