Suppress figures instead of displaying each one and closing it.

5 ビュー (過去 30 日間)
Tyler Lawson
Tyler Lawson 2022 年 11 月 10 日
コメント済み: Tyler Lawson 2022 年 11 月 12 日
% 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 件のコメント
Tyler Lawson
Tyler Lawson 2022 年 11 月 12 日
So I need the .fig file and a .jpg file to save like they currently do. However when running a decent amount at once, I don't want each matlab figure to have to open and then close as it takes time. I tried doing the visibily off but then I cant open the matlab figure later once it is saved unless I open matlab and run a code to view it.

サインインしてコメントする。

回答 (1 件)

Simon Chan
Simon Chan 2022 年 11 月 10 日
Set the figure to invisble and use f as the handle in the following example if needed.
f = figure('Visible','off')
  1 件のコメント
Tyler Lawson
Tyler Lawson 2022 年 11 月 12 日
I tried this... however, the file saves and then I cannot open the figure to make changes or zoom in or whatever later if I wanted.

サインインしてコメントする。

カテゴリ

Find more on Migrate GUIDE Apps in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by