Filter löschen
Filter löschen

Change code to grab a single file

2 Ansichten (letzte 30 Tage)
Tyler
Tyler am 21 Dez. 2022
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

Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by