-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadBinFile.m
More file actions
32 lines (23 loc) · 789 Bytes
/
readBinFile.m
File metadata and controls
32 lines (23 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function dataMatrix = readBinFile(filename,numCols,dataType)
%filename = 'NiDaqInput0.bin'; % Replace with your actual filename
%numCols = 5; % Replace with the known number of columns
%dataType = 'double'; % Change if data is stored in a different format
% Open the file
fid = fopen(filename, 'rb');
if fid == -1
error('Failed to open file.');
end
% Read the data
data = fread(fid, inf, dataType);
% Close the file
fclose(fid);
% Determine the number of rows
numRows = length(data) / numCols;
if mod(numRows, 1) ~= 0
error('File size is not consistent with the specified number of columns.');
end
% Reshape into a matrix
dataMatrix = reshape(data, numCols, [])'; % Transpose to get correct row-wise format
% Display first few rows
disp(dataMatrix(1:min(5, end), :));
end