Matlab script generating corrupted workspace

8 Ansichten (letzte 30 Tage)
MARTINA ROGERS
MARTINA ROGERS am 27 Jun. 2022
Beantwortet: MARTINA ROGERS am 29 Jun. 2022
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!

Akzeptierte Antwort

MARTINA ROGERS
MARTINA ROGERS am 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.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 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 Kommentare
MARTINA ROGERS
MARTINA ROGERS am 27 Jun. 2022
Hi Walter, this also happens when I save the workspace to an external ssd. Could you clarify your first suggestion? I am saving the workspace by highlighting all of its contents and saving as ... (I've chosen locations on my external drive and on the computer itself which automatically uploads to OneDrive). Is there an aternative way of saving that might work?
I also find it weird that I can save all of my workspaces generated from each section of the script to the same file (in my external ssd) and they will all load fine until that specific line in the code...
Thanks!
Walter Roberson
Walter Roberson am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by