How can I read in a very large DAT file from xPC Target when I keep running out of memory using READXPCFILE in xPC Target 4.2 (R2009b)?

4 views (last 30 days)
xPC Target has created a very large DAT file after its simulation. I wish to inspect this data in MATLAB but when I try to read the DAT file using READXPCFILE, I run out of memory.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Oct 2009
You can read in a very large DAT file from xPC Target in partitions by use of the FSEEK and FREAD commands in xPC Target 4.2 (R2009b).
To do this, you need to know
a)The header size in the DAT file
b)The number of signals and the type of signal (int8, double)
If you had a DAT file of 11 signals saved as type double, the following code illustrates how you may retrieve this information piece-wise. Depending on your specific computer setup, you may need to read in shorter (or longer) partitions of data and save it accordingly.
fclose('all')
fid=fopen('DATA1.DAT');
ftest=fread(fid,5000)
extractinfo=readxpcfile(ftest) %inspect at command window output
%note that headersize =512 (for this case)
headersize=512;
fclose('all')
fid=fopen('DATA1.DAT');
[header,count1]=fread(fid,headersize);
l=88000; %=11signals * 8 bytes * 1000 time steps
[a,count2]=fread(fid,l);
str1=readxpcfile([header;a]);
%At this point you may save your variables str1 and str2, etc. to a MAT
%file and clear your workspace to free up the memory. You may wish to
%relaunch MATLAB as well
save str1.mat str1
clear
fclose(fid)
fid=fopen('DATA1.DAT');
%seek to the place in the file where you left off last time.
fseek(fid, count1+count2,'bof')
[a,count3]=fread(fid,l);
str2=readxpcfile([header;a]);
save str2.mat str2
clear
fclose(fid)
fid=fopen('DATA1.DAT');
%To confirm that the data lines up correctly, plot it
plot([str1.data;str2.data])

More Answers (0)

Categories

Find more on Install Products in Help Center and File Exchange

Products


Release

R2009b

Community Treasure Hunt

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

Start Hunting!