So I have an m. file script that contains 2 functions.
The first one (that's loaded when I run the script) and the second.
Each of them has a different GUI setup and different text in text boxes (sorry for tautology).
My program is about calculating stuff using economic formulas, and the final version of the program is going to have about 50 formulas in it. AND I don't want to make 50 separate scripts for each formula. What I want is to be able to switch between formulas inside one script.
So I made a specific push button for that purpose (code below) but when I press it nothing happens.
Can someone who's experienced enough tell me what did I do wrong? (I'm new to MATLAB).
Let me know if more information is needed, or the question is not clear enough. Thanks in advance!
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);
Here's the whole script:
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) do?SecondScriptcode and step in? Since the problem seems in this function, perhaps you might post it.SecondScript-function, as I (as well as il_raffa) mentioned before the problem seems to be with that function.