【发布时间】:2015-07-06 18:31:38
【问题描述】:
所以我有一个 m。包含 2 个函数的文件脚本。
第一个(在我运行脚本时加载)和第二个。
它们中的每一个都有不同的 GUI 设置和文本框中的不同文本(抱歉重言式)。
我的程序是关于使用经济公式计算东西的,该程序的最终版本将包含大约 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 没有显示任何错误消息。
-
您是否尝试在
SecondScript代码中设置断点并介入?由于问题似乎在这个函数中,也许你可以发布它。 -
好的,我发布了整个脚本,希望对您有所帮助。
-
你还没有发布
SecondScript-函数,因为我(以及il_raffa)之前提到的问题似乎与该函数有关。
标签: matlab