我想使用这两个按钮,并在选择文件夹后更改文本字段。然后将图片和jpg文件保存到相应的文件夹中。

4次浏览(最近30天)
这段代码真的很接近完成!我希望能够使用按钮来选择文件夹,其中保存在代码期间创建的图的格式。我还想有文本框的按钮更新后,选择文件夹的权利。
classdefSEdataAPPv1_09 < matlab.apps.AppBase
与应用程序组件对应的属性
属性(Access = public)
UIFigurematlab.ui.Figure
GridLayoutmatlab.ui.container.GridLayout
LeftPanelmatlab.ui.container.Panel
FolderSelectionButtonGroupmatlab.ui.container.ButtonGroup
MultipleFoldersButtonmatlab.ui.control.RadioButton
SingleFolderButtonmatlab.ui.control.RadioButton
Version109Labelmatlab.ui.control.Label
图像matlab.ui.control.Image
RightPanelmatlab.ui.container.Panel
GridLayout2matlab.ui.container.GridLayout
JPEGSaveLocationButtonmatlab.ui.control.Button
MatLabFigureSaveLocationButtonmatlab.ui.control.Button
JPEGSaveLocationEditFieldmatlab.ui.control.EditField
MatLabFigureSaveLocationEditFieldmatlab.ui.control.EditField
matlab.ui.control.Lamp
STARTButtonmatlab.ui.control.Button
结束
%与具有自动回流流的应用程序对应的属性
属性(Access = private)
onePanelWidth = 576;
结束
%处理组件事件的回调
方法(Access = private)
按下按钮的函数:STARTButton
函数STARTButtonPushed(应用程序、事件)
这段代码获取RAW SE数据,将文件转换为文本(.txt)文件和
然后将HIGH, MID和LOW频率组合到一个文本文件中
%可以被多次选择,这些被选择的文件将被放在一个
%的阴谋。
输入要搜索的目录
Parentdirectory = uigetdir(‘*’选择包含文件夹的文件夹);
如果isnumeric (parentdirectory);返回结束%的用户取消
Dinfo = dir(parentdirectory);
Dinfo (~[Dinfo .isdir]) = [];删除普通文件
dinfo (ismember ({dinfo.name}, {“。”“. .”})) = [];%去除。和. .
K = 1:长度(dinfo)
directory = fullfile(dinfo(K)。文件夹,dinfo (K) . name);
列出文件夹中的所有项目
fileList = dir(目录);
从列表中删除子文件夹(即只保留文件)
fileList(vertcat(fileList.isdir)) = [];
数字
持有
使用文件夹作为绘图标题
[ParentFolderPath] = fullfile(目录);
[~, ParentFolderName] = fileparts(ParentFolderPath);
标题(ParentFolderName,“字形大小”, 20);
遍历每个文件,复制它并给出新的扩展名:.txt
i = 1:数字(fileList)
file = fullfile(fileList(i).name);
[tempDir, tempFile] = fileparts(file);
status = copyfile(file, fullfile(tempDir, [tempFile,]' . txt ')));
结束
组合水平文本文件
%location = input("测试点的位置:","s");
fileName = ParentFolderName +“HORZ NOM.txt”
dL = dir(fullfile(目录,“* HLF * NOM.txt”));
dM = dir(fullfile(目录,“*羟甲基糠醛* NOM.txt”));
dH = dir(fullfile(目录,“*超高频* NOM.txt”));
I = 1:数值(无穷大)
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)];
在继续之前,对这里的每一组做任何事情…
writetable (tD fullfile(目录,文件名));
情节(tD.Frequency tD.SE,“颜色”“蓝”,线宽= 1.5)
持有
结束
组合垂直文本文件
%location = input("测试点的位置:","s");
fileName = ParentFolderName +" VERT NOM.txt"
dL = dir(fullfile(目录,“*甚低频* NOM.txt”));
dM = dir(fullfile(目录,“* VMF * NOM.txt”));
dH = dir(fullfile(目录,“*甚高频* NOM.txt”));
I = 1:数值(无穷大)
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)];
在继续之前,对这里的每一组做任何事情…
writetable (tD fullfile(目录,文件名));
情节(tD.Frequency tD.SE,“颜色”“红色”,线宽= 1.5)
持有
结束
%合并AON文本文件并另存为MR
%location = input("测试点的位置:","s");
fileName = ParentFolderName +“AON.txt”
dL = dir(fullfile(目录,“* HLF * AON.txt”));% salt适合通配符,以匹配命名惯例
dM = dir(fullfile(目录,“*羟甲基糠醛* AON.txt”));
dH = dir(fullfile(目录,“*超高频* AON.txt”));
I = 1:数值(无穷大)%必须有相同的数字Lo, Mid, High -首先添加错误检查
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)];
在继续之前,对这里的每一组做任何事情…
writetable (tD fullfile(目录,文件名))
情节(tD.Frequency tD.SE,“颜色”# 588146的,线宽= 1.5)
持有
结束
合并FTN文本文件,另存为DR
%location = input("测试点的位置:","s");
fileName = ParentFolderName +“FTN.txt”
dL = dir(fullfile(目录,“* HLF * FTN.txt”));% salt适合通配符,以匹配命名惯例
dM = dir(fullfile(目录,“*羟甲基糠醛* FTN.txt”));
dH = dir(fullfile(目录,“*超高频* FTN.txt”));
I = 1:数值(无穷大)%必须有相同的数字Lo, Mid, High -首先添加错误检查
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)];
在继续之前,对这里的每一组做任何事情…
writetable (tD fullfile(目录,文件名))
情节(tD.Frequency tD.SE,“颜色”“# 9 f9f9f”,线宽= 1.5)
结束
网格
%根据字母顺序改变颜色
新颜色= {“蓝”“红色”“# 72 a75b”# 999999的“# 0003 ff”};
colororder (newcolors);
%设置及格/不及格线
PFx = [10000 10000000 1000000000];
PFy = [20 80 80];
将及格/不及格线添加到绘图中
情节(PFy可以,“颜色”“绿色”“线宽”, 1.5);
更改图例位置并从图例中删除通过/失败线
Lgnd =传说(“位置”“西北”);
Lgnd =传说(“水平”“垂直”“先生”“博士”“mil - std - 188 - 125 - 1”);
Lgnd。FontSize = 14;
%标记x轴和y轴
包含(的频率(赫兹)“字形大小”, 18岁,“FontWeight”“大胆”);
ylabel (屏蔽效果(dB)“字形大小”, 18岁,“FontWeight”“大胆”);
设置两个轴的比例
集(gca),“XScale”“日志”“ylim”200年[-10]);
删除绘图上的值*注释掉
%设置(gca、“xticklabel”,[],“yticklabel”,[]);将它们加回*
%设置(gca、“xticklabel”,[],“yticklabel”,[]);
将网格线设置为虚线、颜色
集(gca),“gridlinestyle”“——”);
集(gca),“gridalpha”, 0.5);
集(gca),“GridColor”“黑”);
集(gca),“颜色”“# ececec”);
集(gca),“颜色”“# ececec”);
集(gcf,“windowstate”“最大化”);
savefig (ParentFolderPath);
exportgraphics (gca ParentFolderPath +“jpg”);
关闭(gcf);
结束
结束
根据ui图宽度改变应用的排列
函数updateAppLayout(应用程序、事件)
currentFigureWidth = app. ufigue . position (3);
如果(currentFigureWidth <= app.onePanelWidth)
%改变为2x1网格
app.GridLayout.RowHeight = {313,313};
app.GridLayout.ColumnWidth = {“1 x”};
app.RightPanel.Layout.Row = 2;
app.RightPanel.Layout.Column = 1;
其他的
%变为1x2网格
app.GridLayout.RowHeight = {“1 x”};
app.GridLayout.ColumnWidth = {220,“1 x”};
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
结束
结束
结束
%组件初始化
方法(Access = private)
创建用户界面图和组件
函数createcomponent(应用)
创建UIFigure并隐藏,直到所有组件都被创建
app. ufig = ufig (“可见”“关闭”);
app.UIFigure.AutoResizeChildren =“关闭”
app. ufigue . position = [100 100 640 313];
app.UIFigure.Name =MATLAB应用程序的
app. ufigue . sizechangedfcn = createCallbackFcn(app, @updateAppLayout, true);
%创建GridLayout
app.GridLayout = uigridlayout(app.UIFigure);
app.GridLayout.ColumnWidth = {220,“1 x”};
app.GridLayout.RowHeight = {“1 x”};
app.GridLayout.ColumnSpacing = 0;
app.GridLayout.RowSpacing = 0;
app.GridLayout.Padding = [0 0 0 0];
app.GridLayout.Scrollable =“上”
创建左面板
app.LeftPanel = uipanel(app.GridLayout);
app.LeftPanel.BackgroundColor = [1 1 1];
app.LeftPanel.Layout.Row = 1;
app.LeftPanel.Layout.Column = 1;
%创建映像
app.Image = uiimage(app.LeftPanel);
app.Image.Position = [6 173 208 134];
app.Image.ImageSource =“Jaxon_R_LOGO.png”
创建Version109Label
app.Version109Label = uilabel(app.LeftPanel);
app.Version109Label。FontSize = 24;
app.Version109Label。位置= [40 159 139 30];
app.Version109Label。文本=1.09版本的
创建文件夹选择按钮组
app.FolderSelectionButtonGroup = uibuttongroup(app.LeftPanel);
app.FolderSelectionButtonGroup.BorderType =“没有”
app.FolderSelectionButtonGroup.TitlePosition =“centertop”
app.FolderSelectionButtonGroup.Title =“选择文件夹”
app.FolderSelectionButtonGroup.BackgroundColor = [1 1 1];
app.FolderSelectionButtonGroup.FontSize = 24;
app.FolderSelectionButtonGroup.Position = [6 21 208 104];
创建SingleFolderButton
app.SingleFolderButton = uiradiobutton(app.FolderSelectionButtonGroup);
app.SingleFolderButton.Text =“单文件夹”
app.SingleFolderButton.FontSize = 18;
app.SingleFolderButton.Position = [11 36 128 31];
创建MultipleFoldersButton
app.MultipleFoldersButton = uiradiobutton(app.FolderSelectionButtonGroup);
app.MultipleFoldersButton.Text =“多个文件夹”
app.MultipleFoldersButton.FontSize = 18;
app.MultipleFoldersButton.Position = [11 4 149 33];
app.MultipleFoldersButton.Value = true;
%创建右面板
app.RightPanel = uipanel(app.GridLayout);
app.RightPanel.BackgroundColor = [1 1 1];
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
%创建GridLayout2
app.GridLayout2 = uigridlayout(app.RightPanel);
app.GridLayout2。ColumnWidth = {“0.5倍”“1 x”};
app.GridLayout2。RowHeight = {“1 x”“1 x”84};
app.GridLayout2。BackgroundColor = [1 1 1];
%创建STARTButton
app. startbutton = uibutton(应用程序。GridLayout2,“推”);
app. startbutton . buttonpushedfcn = createCallbackFcn(app, @ startbuttonpressed, true);
app.STARTButton.FontSize = 48;
app.STARTButton.Layout.Row = 3;
app.STARTButton.Layout.Column = 2;
app.STARTButton.Text =“开始”
%创建灯
app.Lamp = uilamp(app.GridLayout2);
app.Lamp.Layout.Row = 3;
app.Lamp.Layout.Column = 1;
app.Lamp.Color = [1 0 0];
创建MatLabFigureSaveLocationEditField
app. matlabfiguresavelocationeditfield = uieditfield(app. matlabfiguresavelocationeditfield)GridLayout2,“文本”);
app.MatLabFigureSaveLocationEditField.HorizontalAlignment =“中心”
app.MatLabFigureSaveLocationEditField.FontSize = 18;
app.MatLabFigureSaveLocationEditField.FontColor = [1 0 0];
app.MatLabFigureSaveLocationEditField.Layout.Row = 1;
app.MatLabFigureSaveLocationEditField.Layout.Column = 2;
创建JPEGSaveLocationEditField
app. jpegsavelocationeditfield = uieditfield(app。GridLayout2,“文本”);
app.JPEGSaveLocationEditField.HorizontalAlignment =“中心”
app.JPEGSaveLocationEditField.FontSize = 18;
app.JPEGSaveLocationEditField.FontColor = [1 0 0];
app.JPEGSaveLocationEditField.Layout.Row = 2;
app.JPEGSaveLocationEditField.Layout.Column = 2;
创建MatLabFigureSaveLocationButton
app. matlabfiguresavelocationbutton = uibutton(app. matlabfiguresavelocationbutton)GridLayout2,“推”);
app.MatLabFigureSaveLocationButton.WordWrap =“上”
app.MatLabFigureSaveLocationButton.FontSize = 18;
app.MatLabFigureSaveLocationButton.Layout.Row = 1;
app.MatLabFigureSaveLocationButton.Layout.Column = 1;
app.MatLabFigureSaveLocationButton.Text =MatLab图形保存位置
创建JPEGSaveLocationButton
app. jpegsavelocationbutton = uibutton(app. jpegsavelocationbutton)GridLayout2,“推”);
app.JPEGSaveLocationButton.WordWrap =“上”
app.JPEGSaveLocationButton.FontSize = 18;
app.JPEGSaveLocationButton.Layout.Row = 2;
app.JPEGSaveLocationButton.Layout.Column = 1;
app.JPEGSaveLocationButton.Text =“JPEG保存位置”
%显示所有组件创建完成后的图形
app.UIFigure.Visible =“上”
结束
结束
%应用程序创建和删除
方法(Access = public)
%构造应用程序
函数app = SEdataAPPv1_09
创建用户界面图和组件
createcomponent(应用)
在应用程序设计器中注册应用程序
app.UIFigure registerApp(应用)
如果Nargout = 0
清晰的应用程序
结束
结束
%在删除应用程序之前执行的代码
函数删除(应用)
删除应用程序时删除用户界面图
删除(app.UIFigure)
结束
结束
结束

接受的答案

凯文·霍利
凯文·霍利 2022年12月2日
添加属性变量
属性
JPEGSaveLocation
MATLABFigureSaveLocation
结束
添加回调到“JPEG保存位置”按钮
app.JPEGSaveLocation = uigetdir(‘*’选择保存JPEG的文件夹);
JPEGSaveLocationEditField。Value = app.JPEGSaveLocation;
添加回调到“MATLAB图保存位置”按钮
app.MATLABFigureSaveLocation = uigetdir(‘*’“选择文件夹以保存MATLAB图形”);
MATLABFigureSaveLocationEditField。Value = app.MATLABFigureSaveLocation;

更多答案(0)

2022世界杯八强谁会赢?


释放

R2021b

世界杯预选赛小组名单社区寻宝

在MATLAB Central中找到宝藏,并发现社区如何帮助您!世界杯预选赛小组名单

开始狩猎!

Baidu
map