How to read multiple .bin files which are in one folder

8 ビュー (過去 30 日間)
C PRASAD
C PRASAD 2022 年 9 月 6 日
回答済み: Arjun 2025 年 1 月 6 日
i want to rad only .bin files and plot them using matlab
  3 件のコメント
C PRASAD
C PRASAD 2022 年 9 月 7 日
Thanks for the answer but it is not working for binary files
Stephen23
Stephen23 2022 年 9 月 7 日
編集済み: Stephen23 2022 年 9 月 7 日
"Thanks for the answer but it is not working for binary files"
Both approaches work for binary files, they will work for any files.
Of course you need to select an appropriate function for importing your binary file (it is not in the scope of a general help page to specify a function for every possible file format, that is your task).
Please upload two sample files by clicking the paperclip button.

サインインしてコメントする。

回答 (1 件)

Arjun
Arjun 2025 年 1 月 6 日
I understand that you want to read multiple files from a folder which are ending with a .BIN extension.
You can refer to the following workflow for doing so:
  • Use the 'dir' function of MATLAB to list all the .Bin files present in the directory.
  • Iterate over the list of .BIN files and process them one by one.
  • Use 'fopen' to open the files.
  • Use 'fread' to read data content from the file.
  • Use 'fclose' to close the file after obtaining desired data.
Kindly refer to the following skelton code for reference:
% Extracting files ending with .bin extension
folderPath = 'path/to/your/folder';
filePattern = fullfile(folderPath, '*.bin');
binFiles = dir(filePattern);
% Iterate over the binary files one by one and process as needed
for k = 1:length(binFiles)
% Get the full file path
baseFileName = binFiles(k).name;
fullFileName = fullfile(folderPath, baseFileName);
% Open the file, opening file in reading mode
fileID = fopen(fullFileName, 'rb');
% Check if the file opened successfully
if fileID == -1
error('Cannot open file: %s', fullFileName);
end
% Read the data using fread. This will store data in column vector
% Read documentation of this function for other modes of reading.
data = fread(fileID);
% Close the file
fclose(fileID);
% Once the file has been read, you can plot the data as needed.
end
Please find attached documentation of functions used for reference:
I hope this will help!

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by