Saving and reloading a table

66 次查看(过去 30 天)
Timothy
Timothy 2023-8-18
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.

回答(1 个)

Image Analyst
Image Analyst 2023-8-18
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!

Translated by