Clear Filters
Clear Filters

Saving and reloading a table

62 views (last 30 days)
Timothy
Timothy on 18 Aug 2023
Answered: Image Analyst on 18 Aug 2023
Hello,
I created a livescript for data, and the result is a table. I open the live script and multiply several variables in the table in order to transform them into the necessary data. I then save the new table. Whenever I try to load it, however, the following occurs:
>> load('Tex.mat')
Error using load
Unable to read MAT-file C:\Users\(filelocation). File might be corrupt.
How do I save and access this table within MATLAB? Thank you.

Answers (1)

Image Analyst
Image Analyst on 18 Aug 2023
That should work. You'll need to show us how you actually saved it with the save function.
What I'd do is
%------------------------------------------------------------------------------------
% Save table.
folder = pwd; % Specify some folder where the output file will be saved to.
fullFileName = fullfile(folder, 'Tex.mat'); % Get the full path : folder plus name.
save(fullFileName, 'newTable'); % Save table "newTable" into a .mat file.
%------------------------------------------------------------------------------------
% Recall table.
if ~isfile(fullFileName) % Make sure file exists.
% Then the file was not found.
errorMessage = sprintf('ERROR: The file "%s" does not exist', fullFileName)
uiwait(errordlg(errorMessage));
return; % Bail out since file was not found.
end
% If we get here, the file exists. First, read the mat file into a structure.
s = load(fullFileName) % I like to leave the semicolon off so it prints all field names to the command window.
% Extract the newTable field of the structure into its own variable for convenience.
recalledTable = s.newTable;

Community Treasure Hunt

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

Start Hunting!