How could I read specific range segments of data by fopen?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
Because my DAQ generated data format was int16 binary file, I wrote a matlab script to read out and process the data after experiment.
However, due to my PC RAM size, the maximum segments I could read were 500000, what if I got 1000000 segments, how could I read out the data start from 500000 to 1000000? Here is the script I wrote in below:
fid = fopen('C:\Program Files (x86)\Gage\CompuScope\CompuScope C SDK\C Samples\Advanced\GageStream2Disk\2021012910um100MHz2_1.dat');
segmentCount = 500000;
size2Read = 3152; %Actual segment size when you acquire data,check the INI file
channelCount = 2; %Channel you used, Single Channel=1, Dual Channel=2
dataint16 = zeros(size2Read, segmentCount,channelCount); %Initialize the array for faster
sizeHeader = 64; %Some unknown header included in the data... typically relating to the info of data
fileheaders = zeros(sizeHeader, segmentCount); %Same, initialize the array to pull out the header
if channelCount == 1
%Read out all the segments of data and header
for iSegmentCount=1:1:segmentCount
for iChannelCount=1:1:channelCount
dataint16(:,iSegmentCount,iChannelCount) = fread(fid,size2Read, 'int16',0, 'ieee-le');
end
fileheaders(:,iSegmentCount) = fread(fid, sizeHeader, 'int16',0, 'ieee-le');
end
else
for iSegmentCount=1:1:segmentCount
tmpSeg = fread(fid,size2Read*2, 'int16',0, 'ieee-le');
for iChannelCount=1:1:channelCount
dataint16(:,iSegmentCount,iChannelCount) = tmpSeg(iChannelCount:2:end);
end
fileheaders(:,iSegmentCount) = fread(fid, sizeHeader, 'int16',0, 'ieee-le');
end
end
fclose(fid);
2 comentarios
dpb
el 31 de En. de 2021
Without us having to figure it out by reading your code, what is the actual data structure of the file?
You can use fseek to move to wherever in the file a given set of data begins for a time record based on the offset from the beginning of the file.
You have to account for the header and organization in the file and number of channels.
Respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!