Reputation: 31
I am new in using MATLAB
and I want to do a simple thing: I want to read a binary file that contains rows like this
32156432
345243867
454154351
35477
5641871
....
I know that the fread()
in MATLAB reads the file byte by byte, but I want to read the value that there is on each line. All values are uint32_t
and the file is generated with a script in C++
with just a printf
, the values are printed in a file like my_file.bin
launching the executable in this way ./executable param1 >> my_file.bin
Upvotes: 0
Views: 419
Reputation: 431
You can use the function fscanf
Sample Code:
fileID = fopen('my_file.bin','w');
x = 32156432;
y = 345243867;
w = 454154351;
fprintf(fileID, '%d\n',x);
fprintf(fileID, '%d\n',y);
fprintf(fileID, '%d\n',w);
fclose(fileID);
fileID = fopen('my_file.bin','r');
formatSpec = '%d';
A = fscanf(fileID, formatSpec);
Upvotes: 2