필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Chen Kevin
Chen Kevin 2021년 1월 31일
댓글: Chen Kevin 2021년 2월 2일
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
dpb
dpb 2021년 1월 31일
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 2021년 2월 2일
Because I have two channels recording simutanously, each segment will be filled in this formate: ch1(3152)ch2(3152)header(64), ch1ch2header, ch1ch2header....

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by