What is the easiest way to embed a text data file into a .m function so that you don't need two files.
8 views (last 30 days)
Show older comments
Commented: Zeb Barber on 1 Nov 2018
I have a function that uses a pre-generated lookup table that is stored as a text file. I would like to embed the text file into the .m file so that I don't have to move both files around.
Guillaume on 1 Nov 2018
Edited: Guillaume on 1 Nov 2018
Load your text file into a variable, however you normally read it in your code, for example:
lookuptable = fileread(yourtextfile);
Then right click on the variable in the variable browser, select 'Save As...' and in the 'Save as type' dropdown change the type from mat file to m file to let matlab autogenerate the code to create that variable.
More Answers (1)
Elias Gule on 1 Nov 2018
I guess you can store your data as part of the code. Your may create an inner function or a subfunctions that initializes your lookup table; you can also store your data as properties of a class.
Find more on MATLAB Report Generator in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!