Change code to grab a single file

3 ビュー (過去 30 日間)
Tyler
Tyler 2022 年 12 月 21 日
The current code takes 3 files and puts them into 1 (SEE COMBINE HORIIZONTAL SECTION) and then reads that newly created file and plots it. However, I need to change it so that it only grabs a single file without the combination process. The folder has the files I need to plot already and no combination of files is needed.
% Enter the directory to search
directory = uigetdir('*',"Select Folder With Files To Be Processed");
% List all items in the folder
fileList = dir(directory);
% Delete the subfolders from the list (i.e. only keep files)
fileList(vertcat(fileList.isdir)) = [];
app.Lamp.Color = 'Yellow'
figure
hold on
% Uses folder as title of plot
[ParentFolderPath] = fullfile(directory);
[~, ParentFolderName] = fileparts(ParentFolderPath);
% Loop through each file, copy it and give new extension: .txt
for i = 1:numel(fileList)
file = fullfile(directory, fileList(i).name);
[tempDir, tempFile] = fileparts(file);
status = copyfile(file, fullfile(tempDir, [tempFile, '.txt']));
end
% Combine HORIZONTAL text files
if app.HorizontalButton.Value == 1;
fileName = ParentFolderName + " HORZ NOM.txt";
dL = dir(fullfile(directory,'*HLF*NOM.txt'));
dM = dir(fullfile(directory,'*HMF*NOM.txt'));
dH = dir(fullfile(directory,'*HHF*NOM.txt'));
for i = 1:numel(inf)
HORZtD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
HORZtD = [HORZtD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
HORZtD = [HORZtD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
writetable(HORZtD,fullfile(directory, fileName));
% Adding the line to the plot with options for color and marker
if app.HorizontalMarkersButton.Value == 1;
Hplot = plot(HORZtD.Frequency,HORZtD.SE,"Color",app.HorizontalColorDropDown.Value,'LineWidth',str2num(app.LineWidthDropDown.Value), ...
Marker=app.HorizontalMarkerDropDown.Value,DisplayName='Horizontal');
else
Hplot = plot(HORZtD.Frequency,HORZtD.SE,"Color",app.HorizontalColorDropDown.Value,'LineWidth',str2num(app.LineWidthDropDown.Value), ...
DisplayName='Horizontal');
hold on
end
end
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by