所以我有一个m。包含2个函数的文件脚本。
第一个(当我运行脚本时加载)和第二个。
他们每个人都有不同的GUI设置和文本框中的不同文本(对于重言式抱歉)。在多个函数之间切换MATLAB
我的程序是关于使用经济公式计算的东西,程序的最终版本将有大约50个公式。而且我不想为每个配方制作50个独立的脚本。我想要的是能够在一个脚本内的公式之间切换。
所以我做了一个特定的按钮(代码如下),但是当我按下它时什么都没有发生。
经验丰富的人能否告诉我我做错了什么? (我是MATLAB新手)。
让我知道是否需要更多信息,或者问题不够清楚。提前致谢!
uicontrol('Style','pushbutton','Position',[136,88,194,27],'String','Next formula','FontSize',10,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685],'CallBack',@SecondScript);
这里是整个脚本:
function FirstScript
clc
clear
close all
global ZatratyNaSozdanieProgProdukta hEditZzpspp hEditZmvspp hEditZobsh
ScreenSize = get(0,'ScreenSize');
set (0, 'DefaultFigureColor', [0.23137255012989 0.443137258291245 0.337254911661148])
hFig = figure('Visible','off','Position',[ScreenSize(3)/2,ScreenSize(4)/2,550,450]);
uicontrol('Style','Pushbutton','Position',[371,136,98,27],'String','Рассчитать','FontSize',10,'FontName','MS Reference Sans Serif','Callback',@CalculateCallback,'BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
uicontrol('Style','pushbutton','Position',[136,88,194,27],'String','Next formula','FontSize',10,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685],'CallBack',@SecondScript);
axes('units','pixels','position',[20 100 200 24],'visible','off');
message = sprintf('Формула определения затрат на\nсоздание программного продукта:\n \nЗ^З^П_С_П_П+З^М^В_С_П_П+З_О_Б_Щ');
text(0,4.6,message,'interpreter','tex','Position',[1.18 8.64166666666667 0],'HorizontalAlignment','center','FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
axes('units','pixels','position',[20 100 200 24],'visible','off');
hTextZzpspp = text(0,4.6,'З^З^П_С_П_П','interpreter','tex','Position',[0.55 4.14166666666666 0],'FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
hEditZzpspp = uicontrol('Style','Edit','Position',[117,150,72,25],'String','','FontSize',10,'FontName','MS Reference Sans Serif');
axes('units','pixels','position',[20 100 200 24],'visible','off');
hTextZmvspp = text(0,4.6,'З^М^В_С_П_П','interpreter','tex','Position',[0.935 4.14166666666666 0],'FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
hEditZmvspp = uicontrol('Style','Edit','Position',[195,150,72,25],'String','','FontSize',10,'FontName','MS Reference Sans Serif');
axes('units','pixels','position',[20 100 200 24],'visible','off');
hTextZobsh = text(0,4.6,'З_О_Б_Щ','interpreter','tex','Position',[1.32 4.05833333333332 0],'FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
hEditZobsh = uicontrol('Style','Edit','Position',[274,150,72,25],'String','','FontSize',10,'FontName','MS Reference Sans Serif');
uicontrol('Style','Text','Position',[370,191,100,29],'String','Результат:','FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
ZatratyNaSozdanieProgProdukta = uicontrol('Style','Text','Position',[370,168,100,23],'String','','FontSize',10,'FontName','MS Reference Sans Serif');
set(hFig,'Visible','on')
function CalculateCallback(~,~)
Zzpspp = str2double(get(hEditZzpspp,'String'));
Zmvspp = str2double(get(hEditZmvspp,'String'));
Zobsh = str2double(get(hEditZobsh,'String'));
Calculation = Zzpspp+Zmvspp+Zobsh;
set(ZatratyNaSozdanieProgProdukta,'String',sprintf('%0.2f',Calculation));
end
end
function SecondScript
clc
clear
close all
global RashodyNaOplatuTrudaRazrabotchikaProgrammy hEditZosnzp hEditZdopzp hEditZotchzp
ScreenSize = get(0,'ScreenSize');
set (0, 'DefaultFigureColor', [0.23137255012989 0.443137258291245 0.337254911661148])
hFig = figure('Visible','off','Position',[ScreenSize(3)/2,ScreenSize(4)/2,550,450]);
uicontrol('Style','Pushbutton','Position',[371,136,98,27],'String','Рассчитать','FontSize',10,'FontName','MS Reference Sans Serif','Callback',@CalculateCallback,'BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
axes('units','pixels','position',[20 100 200 24],'visible','off');
message = sprintf('Формула определения расходов на\nоплату труда разработчика программы:\n \nЗ^З^П_С_П_П+З^М^В_С_П_П+З_О_Б_Щ');
text(0,4.6,message,'interpreter','tex','Position',[1.18 8.64166666666667 0],'HorizontalAlignment','center','FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
axes('units','pixels','position',[20 100 200 24],'visible','off');
hTextZosnzp = text(0,4.6,'З^З^П_С_П_П','interpreter','tex','Position',[0.55 4.14166666666666 0],'FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
hEditZosnzp = uicontrol('Style','Edit','Position',[117,150,72,25],'String','','FontSize',10,'FontName','MS Reference Sans Serif');
axes('units','pixels','position',[20 100 200 24],'visible','off');
hTextZdopzp = text(0,4.6,'З^М^В_С_П_П','interpreter','tex','Position',[0.935 4.14166666666666 0],'FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
hEditZdopzp = uicontrol('Style','Edit','Position',[195,150,72,25],'String','','FontSize',10,'FontName','MS Reference Sans Serif');
axes('units','pixels','position',[20 100 200 24],'visible','off');
hTextZotchzp = text(0,4.6,'З_О_Б_Щ','interpreter','tex','Position',[1.32 4.05833333333332 0],'FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
hEditZotchzp = uicontrol('Style','Edit','Position',[274,150,72,25],'String','','FontSize',10,'FontName','MS Reference Sans Serif');
uicontrol('Style','Text','Position',[370,191,100,29],'String','Результат:','FontSize',12,'FontName','MS Reference Sans Serif','BackgroundColor',[0.756862759590149 0.866666674613953 0.776470601558685]);
RashodyNaOplatuTrudaRazrabotchikaProgrammy = uicontrol('Style','Text','Position',[370,168,100,23],'String','','FontSize',10,'FontName','MS Reference Sans Serif');
set(hFig,'Visible','on')
function CalculateCallback(~,~)
Zosnzp = str2double(get(hEditZosnzp,'String'));
Zdopzp = str2double(get(hEditZdopzp,'String'));
Zotchzp = str2double(get(hEditZotchzp,'String'));
Calculation = Zosnzp+Zdopzp+Zotchzp;
set(RashodyNaOplatuTrudaRazrabotchikaProgrammy,'String',sprintf('%0.2f',Calculation));
end
end
的一个符合看起来不错!但回调函数('SecondScript')是做什么的? –
它加载完全不同的程序(计算器)与其独特的界面和十几个参数来计算。但它不起作用!而最让我惊讶的是,MATLAB不显示任何错误消息。 – Johnnik
您是否尝试将断点设置为'SecondScript'代码并加入?由于这个问题似乎在这个功能,也许你可能会发布它。 –