binary into matlab workspace

조회 수: 3 (최근 30일)
Baba
Baba 2011년 11월 21일
I have a large number of bin files that I'm converting and importing the data into the matlab workspace into variable X for processing. Data is a column of numbers.
X=convert(i,pwd);
convert is a function which converts binary files in pwd directory and pulls out column i from each file and concatenates and puts into X.
What I'd like to do is
when length(X) = length(files(pwd)/2; or some value set by me
Create X1=convert(i,pwd); <-- but start i where X left off and not from begining of bin file. And so on for X2
So Id like to basically split X into X1 X2 .... which are individually small enough to fit into memory and then process them.
If I could somehow pause the execution and redirect where convert stores data without disturbing anything else.

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 21일
Sorry, you are going to have to "disturb" your code interface to handle that. For example, you could have convert() output a second output that was the ftell() value of the place it left off reading, and convert() could take an second input that would be a maximum length, and a third input that would be an fseek() position to start from.
Putting the length constraint to the actual reading should not be difficult; there is an optional size parameter for fread().
  댓글 수: 2
Baba
Baba 2011년 11월 21일
This is my getchan function:
function [DATA] = convert(chan,wd)
% Search for .bin files in the wd directory
DATA=[];
% Loop over every .bin file and build up DATA
for i=1:length(files)
% Make sure we're reading from the wd directory
[d] = readbin (fullfile(wd,files(i).name));
% Append the first column of what we read to DATA
data=(d(:,chan));
DATA=[DATA; data];
end
end
Walter Roberson
Walter Roberson 2011년 11월 21일
Yes, you are definitely going to need to "disturb" that interface. You want to break the data when "number of files divided by 2" *samples* have been read, even though each file might contain thousands of samples. For example if there were 10 files in the directory, you have asked to break after 10/2 = 5 *samples*, which would be like 2048 variables if each of the 10 files contained 1024 samples.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by