フィルターのクリア

I'm trying to write a code that import several data from multiple folder

1 回表示 (過去 30 日間)
Ibrahim Soussi
Ibrahim Soussi 2016 年 4 月 14 日
コメント済み: Ibrahim Soussi 2016 年 4 月 14 日
I have a folder that contains 8 sub folders the each sub contains a data that has the same name in the other folder for example main folders name is rotation in the sub theirs side 1 to 8 in each folder theirs a FX.txt data how can i write a code that is going to read each data from the multiple folder i have no idea

採用された回答

Orion
Orion 2016 年 4 月 14 日
Hi,
you need something like this (adapt it to your path and folders)
% Path of the main folder : Rotation
yourpath = 'C:\Users\YourName\Documents\MATLAB\Rotation';
% Get all the subfolders
ContentInFold = dir(yourpath);
SubFold = ContentInFold([ContentInFold.isdir]); % keep only the directories
% Loop on each folder
MyData = [];
for i = 3:length(SubFold) % start at 3 to skip . and ..
filetoread = fullfile(yourpath,SubFold(i).name,'FX.txt');
% then type your code to read the text files and store in one variable
fileID = fopen(filetoread);
MyData{end+1} = textscan(fileID,'%s\n'); % the format depends of your files
fclose(fileID);
end
  2 件のコメント
Ibrahim Soussi
Ibrahim Soussi 2016 年 4 月 14 日
thank you for your help however it did work this is the folder and my data view i need to open the folder and get the fx data from each folder
<<
>>
Ibrahim Soussi
Ibrahim Soussi 2016 年 4 月 14 日

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

その他の回答 (1 件)

Orion
Orion 2016 年 4 月 14 日
The code I showed should work. You just need to adapt it.
% Path of the main folder : Rotation
yourpath = 'H:\Inspection ProjectData\rotation1';
% Get all the subfolders
ContentInFold = dir(yourpath);
SubFold = ContentInFold([ContentInFold.isdir]); % keep only the directories
% Loop on each folder
MyData = [];
for i = 3:length(SubFold) % start at 3 to skip . and ..
filetoread = fullfile(yourpath,SubFold(i).name,'fx.txt'); % <- this is the "fx.txt" file of the ith subfolders
% then type your code to read the text files and store in one variable
fileID = fopen(filetoread);
MyData{end+1} = textscan(fileID,'%s\n'); % the format depends of your files
fclose(fileID);
end
the only line you should probably change is
MyData{end+1} = textscan(fileID,'%s\n');
because this depends on how the data are written in your file and I can't guess it.
  1 件のコメント
Ibrahim Soussi
Ibrahim Soussi 2016 年 4 月 14 日
thank you so much my data are numbers that cam from sensors in a lab

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

カテゴリ

Help Center および File ExchangeData Preparation Basics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by