simulink 'tofile' block creates an unloadable mat file

I have a simulink test case by sampling a continuous time signal for 0.125 seconds with sample rate of 32MHz, and the sampled data is sent to file 'a.mat' with simulink 'toFile' block. However, after simulation I could not load file 'a.mat' for post processing. Matlab complains
'??? Error using ==> load Can't read file Z:a.mat.
If I simulated for more than 0.125 seconds, I noticed that file 'a.mat' did not increase its size. I wonder if 'toFile' block has a maximum file size limitation.
On the other hand, if I simulate for a shorter time, say, 0.1 seconds, 'a.mat' size became smaller, but I still cannot load it from Matlab, until I reduced the simulation time substantially. I again wonder if 'toFile' has a potential problem of corrupting the output file for long simulations.
Thanks in advance for your response,
Jianping

1 Comment

Sorry, longer simulation time does increase the mat file size, which nullifies my first question about maximum file size limitation. However, the file is not loadable if simulation time is longer than 32.8ms (0.0328 seconds).
The test bench is very simple: a sinusoidal source of 1kHz, and a 'toFile' block of sampling frequency of 32MHz.

Sign in to comment.

 Accepted Answer

I believe there is a problem with MATLAB being unable to load large MAT-files created by the "To File" block - how many samples does your model compute in 0.1 seconds? When you say "If I simulated for more than 0.125 seconds, I noticed that file 'a.mat' did not increase its size." - how do you figure out the size? Do you use OS commands, or are you looking at the size in the MATLAB Current Folder panel? I would rely more on the former.
I'm not sure what version of MATLAB you are using, but the new matlab.io.MatFile class in R2011b lets you load parts of a large MAT-file. Try these commands to determine the size of your logged data:
matObj = matfile('myFile.mat')
sizeMyVar = size(matObj,'myVar')
If the variable is too large, try loading it in parts.

9 Comments

I made mistake when I said that mat file 'did not increase its size' as I pointed out in my comment right after the question. The file size did change as simulation time increases - the size is indicated by OS.
I'm using matlab 2007b and the test bench is quite simple: a "Sin Wave" block and a "To File" block. Since the sampling time is 1/32e6 (sample rate of 32MHz), the number of samples in 0.1 seconds is 0.1*32e6=3.2 millions.
What size is considered to be large for a mat file created by "To File" and Matlab will have problem? Is there a work around solution for version R2007b?
Thanks again,
Jianping
I don't know what the exact size-limit is actually. What you could do is put multiple "To File" blocks inside Enabled Subsystems and enable each subsystem in turn for 32ms each - that way, the data is split across several MAT-file blocks. I know this is very cumbersome, but can't think of a better way.
This is indeed cumbersome. For my curiosity, what is the reason that 'To File' block can create such a problem to Matlab, since Matlab can handle mat file with much larger size? The problematic mat file from 'To File' block is less than 30M, but Matlab can load mat file of much larger sizes. Is Simulink team aware of this problem? 'To File' block is very useful because it can speed up simulation substantially by freeing up large amount of memory without dumping too much data to workspace by 'To Workspace' block in case that millions of samples are necessary for post processing.
Thanks,
Jianping
Jianping: Like I said in my initial reply - from what I understand, the problem is due to MATLAB's limitation - this is not a problem with the To File block at all. Are you certain that you have been able to load files larger than 30MB in MATLAB?
(Also, to be certain - you have always used only 32-bit or 64-bit machines right? 64-bit machines can in general load large amounts of data)
I'm using 32-bit machine, and I don't think mat file is limited to only 30M by Matlab on a 32-bit machine.
The following link talks about mat file sizes, and it mentioned that matlab can load uncompressed mat file of 100M (in the last section):
http://www.mathworks.com/help/techdoc/import_export/braidzi-1.html#braid3s
By the way, Matlab help on "MAT-Files Preferences" says that starting in MATLAB Version 7.3, you can save data that is larger than 2 GB...
Jianping: I have to admit that my knowledge of the operation of the To File block and MAT-files is somewhat limited. Perhaps you could report this issue to MathWorks Tech Support, so that they can forward it to the appropriate development teams? Customer reported issues are usually assigned higher priority. You might even be able to get a more authoritative answer.
Thanks, and I appreciate your time,
Jianping

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!