Saving and reloading a table
조회 수: 69 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Image Analyst
2023년 8월 18일
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;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!