MATLAB Answers

Saving data array in Matlab data file (.mat) in App Designer

4 views (last 30 days)
Hello dear mates,
I have a set of data array and I am using App Designer. What is the syntax to save the data array in (.mat) file extension? Showing an example can be the best, thank you!

Accepted Answer

Walter Roberson
Walter Roberson on 20 Sep 2021
save('YourFileName.mat', 'NameOfVariable', 'AnotherVariable')
Note that if the values you want to save are currently stored within app or a graphic object, then you need to extract them into a local variable in the name you want them to appear in the .mat . For example,
x_range_start = app.Edit1.Value;
x_range_end = app.Edit2.Value;
save('x_range.mat', 'x_range_start', 'x_range_end');
It is often a good idea to keep track of the directory the user wants to write into, and build the file name instead of using a fixed filename. For example,
results_dir = app.Edit7.Value;
filename = fullfile(results_dir, 'x_range.mat');
x_range_start = app.Edit1.Value;
x_range_end = app.Edit2.Value;
save(filename, 'x_range_start', 'x_range_end')
Notice when you do this, that you do not pass in 'filename' . Use the ' ' when you want to pass in a literal text string; use a variable without surrounding ' ' if you want MATLAB to examine the value of the variable to find the text string.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!