Suppress figures instead of displaying each one and closing it.
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% This code takes RAW SE data, turns the files into text (.txt) files and
% then combines the HIGH, MID, and LOW frequency into one text file which
% can be then multi-selected and those selected files will be put onto a
% plot.
% Enter the directory to search
parentdirectory = uigetdir('*', 'Select Folder with folders inside it');
if isnumeric(parentdirectory); return; end;
dinfo = dir(parentdirectory);
dinfo(~[dinfo.isdir]) = []; %remove ordinary files
dinfo(ismember({dinfo.name}, {'.', '..'})) = []; %remove . and ..
for K = 1 : length(dinfo)
directory = fullfile(dinfo(K).folder, dinfo(K).name);
% List all items in the folder
fileList = dir(directory);
% Delete the subfolders from the list (i.e. only keep files)
fileList(vertcat(fileList.isdir)) = [];
figure
hold all
% Uses folder as title of plot
[ParentFolderPath] = fullfile(directory);
[~, ParentFolderName] = fileparts(ParentFolderPath);
title(ParentFolderName,'FontSize',20);
% 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
%location = input("location of test point: ","s");
fileName = ParentFolderName + " HORZ NOM.txt";
dL = dir(fullfile(directory,'*HLF*NOM.txt')); % salt to suit wildcard to match naming convention
dM = dir(fullfile(directory,'*HMF*NOM.txt'));
dH = dir(fullfile(directory,'*HHF*NOM.txt'));
for i = 1:numel(inf) % there must be same number Lo, Mid, High -- add error check first
tD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD = [tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD = [tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(directory, fileName));
plot(tD,"Frequency","SE","Color",'Blue',LineWidth=1.5);
end
% Combine VERTICAL text files
%location = input("location of test point: ","s");
fileName = ParentFolderName + " VERT NOM.txt";
dL = dir(fullfile(directory,'*VLF*NOM.txt')); % salt to suit wildcard to match naming convention
dM = dir(fullfile(directory,'*VMF*NOM.txt'));
dH = dir(fullfile(directory,'*VHF*NOM.txt'));
for i = 1:numel(inf) % there must be same number Lo, Mid, High -- add error check first
tD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD = [tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD = [tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(directory, fileName))
plot(tD,"Frequency","SE","Color",'Red',LineWidth=1.5);
end
% Combine AON text files and save as MR
%location = input("location of test point: ","s");
fileName = ParentFolderName + " AON.txt";
dL = dir(fullfile(directory,'*HLF*AON.txt')); % salt to suit wildcard to match naming convention
dM = dir(fullfile(directory,'*HMF*AON.txt'));
dH = dir(fullfile(directory,'*HHF*AON.txt'));
for i = 1:numel(inf) % there must be same number Lo, Mid, High -- add error check first
tD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD = [tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD = [tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(directory, fileName))
plot(tD,"Frequency","SE","Color",'#588146',LineWidth=1.5);
end
% Combine FTN text files and save as DR
%location = input("location of test point: ","s");
fileName = ParentFolderName + " FTN.txt";
dL = dir(fullfile(directory,'*HLF*FTN.txt')); % salt to suit wildcard to match naming convention
dM = dir(fullfile(directory,'*HMF*FTN.txt'));
dH = dir(fullfile(directory,'*HHF*FTN.txt'));
for i = 1:numel(inf) % there must be same number Lo, Mid, High -- add error check first
tD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD = [tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD = [tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(directory, fileName))
plot(tD,"Frequency","SE","Color",'#9f9f9f',LineWidth=1.5);
end
grid on
% Changing colors based on alphebetic order
newcolors = {'Blue','Red','#72a75b','#999999','#0003ff'};
colororder(newcolors);
% Sets pass/fail line
PFx = [10000 10000000 1000000000];
PFy = [20 80 80];
% Adds pass/fail line to plot
plot(PFx,PFy,'Color','Green','LineWidth',1.5);
% Changes legend location and removes pass/fail line from legend
Lgnd = legend('Location','northwest');
Lgnd = legend('Horizontal','Vertical','MR','DR','MIL-STD-188-125-1');
Lgnd.FontSize = 14;
% Labels both x and y axis
xlabel('Frequency (Hz)','FontSize',18,'FontWeight','bold');
ylabel('Shielding Effectivness (dB)','FontSize',18,'FontWeight','bold');
% Sets both axis scales
set(gca,'XScale','log','ylim',[-10 200]);
% Removes the values on the plot *Comment out to add them back in*
% set(gca,'xticklabel',[],'yticklabel',[]);
% set(gca,'xticklabel',[],'yticklabel',[]);
% Sets grid lines to dashes, colors
set(gca,'gridlinestyle','--');
set(gca,'gridalpha',0.5);
set(gca,'GridColor','Black');
set(gca,'Color','#ececec');
set(gca,'Color','#ececec');
set(gcf,'windowstate','maximized');
exportgraphics(gcf,ParentFolderName + ".jpg");
savefig(ParentFolderName);
close(gcf);
end
2 commentaires
DGM
le 10 Nov 2022
Do you still intend to get the saved figures as output? If not, I'd just define a logical flag that expresses whether plots should be created. Put all the plots inside conditional statements.
createplots = true;
% ...
if createplots
plot(stuff,things);
% ...
end
Is there something wrong with just doing that?
Réponses (1)
Simon Chan
le 10 Nov 2022
Set the figure to invisble and use f as the handle in the following example if needed.
f = figure('Visible','off')
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!