Change code to grab a single file
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!