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 CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by