Azzera filtri
Azzera filtri

How could I read specific range segments of data by fopen?

1 visualizzazione (ultimi 30 giorni)
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 Commenti
dpb
dpb il 31 Gen 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.
Chen Kevin
Chen Kevin il 2 Feb 2021
Because I have two channels recording simutanously, each segment will be filled in this formate: ch1(3152)ch2(3152)header(64), ch1ch2header, ch1ch2header....

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by