Matlab script generating corrupted workspace

5 views (last 30 days)
Hello, novice Matlab user here so please forgive any obvious errors. I have written a script that analyzes a significant amount of data. The script does what I want it to do, generating a Matlab workspace with a combination of tables, doubles, and timetables. However, when I save this workspace and try to reload it, I get an error. Some of the errors I've gotten have been:
Error using load
Cannot read file D:\test2.mat.
and
I've gone through the script section by section, saving and loading the workspaces, and have come upon the line that seems to be causing this (when I save and load its workspace, the workspace says it has loaded but either nothing comes up or the error: Error using load. Unable to read MAT-file D:\chunk11t2.mat. File might be corrupt). The line itself is: fulldayr=fullday(room==1,:); where I essentially have a logic array (room) and I am trying to pull out all the columns of the rows corresponding to when room is equal to 1 to make a new table.
Does anyone have any thoughts on this? I will need to save the workspaces I am generating, there is no way around that. Perhaps an alternative code to the line I am using? Thank you in advance!

Accepted Answer

MARTINA ROGERS
MARTINA ROGERS on 29 Jun 2022
Hi everyone, I'm going to update just in case anyone else runs into this issue. I was able to save and load the workspace if I used the save FileName -v7.3 function at the end of my script. Thanks for everyone's help.

More Answers (1)

Walter Roberson
Walter Roberson on 27 Jun 2022
I wonder if you are accidentally saving code to the mat file?
In any case: do not save() a mat file directly to OneDrive especially (and treat other cloud storage destinations with suspicion.) Save to a local file on your hard drive, and copy the result to OneDrive
  2 Comments
Walter Roberson
Walter Roberson on 29 Jun 2022
It does not make sense to me that you would get an error message about unable to read the mat file on a line that appears to be indexing a variable.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by