フィルターのクリア

Matlab: select data from many DAT files and put them into one file

1 回表示 (過去 30 日間)
ke
ke 2022 年 12 月 9 日
コメント済み: Mathieu NOE 2022 年 12 月 9 日
I need to put a specific data of each file together in order, but I don't know what to use to describe its path. For example, all files have only numbers. I need to put the data in the first row and the sixth column of each file together. Maybe I need to use the for loop, but it is too difficult for me.please write a short piece of code.

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 12 月 9 日
hello
try this , it will loop in your folder and load all dat files
I assumed here readmatrix is the right function to read your file format
%% define path
fileDir = pwd; % or your specific path / folder
S = dir(fullfile(fileDir,'*.dat')); % get list of data files in directory
S = natsortfiles(S); % sort file names into natural order (what matlab dir does not well) , see FEX :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
%% Loop inside folder
for k = 1:length(S) % read data in specified sheet
fileName = S(k).name;
out = readmatrix(fullfile(fileDir, fileName)); % or use a structure (S(k).data ) to store the full data structure
end
  2 件のコメント
ke
ke 2022 年 12 月 9 日
thank you, if I want the data in the first row and sixth column of each dat file, where should I put (1,6)?
Mathieu NOE
Mathieu NOE 2022 年 12 月 9 日
data in the first row = out(1,:)
data in the sixth column = out(:,6)

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by