⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mcaculor.m

📁 matlab写的计数器例子 这是适于初学者掌握matlab深成次开发的一个很好的教学实例
💻 M
📖 第 1 页 / 共 3 页
字号:
        h_opert_num=round(str2num(get(h_state,'string')));
        main_win_num_str=get(h_edit,'string');
        if h_opert_num==1 | h_opert_num==2 | h_opert_num==3 | h_opert_num==4 %按此键之前按了运算符
            if h_sequence_num==0
                set(h_edit,'string','6');
                set(h_sequence,'string','1');
            else
                main_win_num_str=[main_win_num_str,'6'];
                set(h_edit,'string',main_win_num_str);
            end
        else
            if main_win_num_str=='0'%如果当前的数为0,则先清空
                main_win_num_str='';
            end
            if length(main_win_num_str)>=14 %最大的操作数超过1e+14会出错
                errordlg({'友情提示:   操作数不能大于1e+14'},'error');
            end
            main_win_num_str=[main_win_num_str,'6'];
            set(h_edit,'string',main_win_num_str);
        end
    case 'num5'
        h_edit=findobj(0,'tag','MAIN_EDIT');
        h_num9=findobj(0,'tag','MAIN_BUT9');
        h_state=findobj(0,'tag','OPERATION_STATE');
        h_sequence=findobj(0,'tag','OPERATION_SEQUENCE');
        h_opert=findobj(0,'tag','OPERATOR_ONE');
        h_sequence_num=round(str2num(get(h_sequence,'string')));
        h_opert_num=round(str2num(get(h_state,'string')));
        main_win_num_str=get(h_edit,'string');
        if h_opert_num==1 | h_opert_num==2 | h_opert_num==3 | h_opert_num==4 %按此键之前按了运算符
            if h_sequence_num==0
                set(h_edit,'string','5');
                set(h_sequence,'string','1');
            else
                main_win_num_str=[main_win_num_str,'5'];
                set(h_edit,'string',main_win_num_str);
            end
        else
            if main_win_num_str=='0'%如果当前的数为0,则先清空
                main_win_num_str='';
            end
            if length(main_win_num_str)>=14 %最大的操作数超过1e+14会出错
                errordlg({'友情提示:   操作数不能大于1e+14'},'error');
            end
            main_win_num_str=[main_win_num_str,'5'];
            set(h_edit,'string',main_win_num_str);
        end
    case 'num4'
        h_edit=findobj(0,'tag','MAIN_EDIT');
        h_num9=findobj(0,'tag','MAIN_BUT9');
        h_state=findobj(0,'tag','OPERATION_STATE');
        h_sequence=findobj(0,'tag','OPERATION_SEQUENCE');
        h_opert=findobj(0,'tag','OPERATOR_ONE');
        h_sequence_num=round(str2num(get(h_sequence,'string')));
        h_opert_num=round(str2num(get(h_state,'string')));
        main_win_num_str=get(h_edit,'string');
        if h_opert_num==1 | h_opert_num==2 | h_opert_num==3 | h_opert_num==4 %按此键之前按了运算符
            if h_sequence_num==0
                set(h_edit,'string','4');
                set(h_sequence,'string','1');
            else
                main_win_num_str=[main_win_num_str,'4'];
                set(h_edit,'string',main_win_num_str);
            end
        else
            if main_win_num_str=='0'%如果当前的数为0,则先清空
                main_win_num_str='';
            end
            if length(main_win_num_str)>=14 %最大的操作数超过1e+14会出错
                errordlg({'友情提示:   操作数不能大于1e+14'},'error');
            end
            main_win_num_str=[main_win_num_str,'4'];
            set(h_edit,'string',main_win_num_str);
        end
    case 'num3'
        h_edit=findobj(0,'tag','MAIN_EDIT');
        h_num9=findobj(0,'tag','MAIN_BUT9');
        h_state=findobj(0,'tag','OPERATION_STATE');
        h_sequence=findobj(0,'tag','OPERATION_SEQUENCE');
        h_opert=findobj(0,'tag','OPERATOR_ONE');
        h_sequence_num=round(str2num(get(h_sequence,'string')));
        h_opert_num=round(str2num(get(h_state,'string')));
        main_win_num_str=get(h_edit,'string');
        if h_opert_num==1 | h_opert_num==2 | h_opert_num==3 | h_opert_num==4 %按此键之前按了运算符
            if h_sequence_num==0
                set(h_edit,'string','3');
                set(h_sequence,'string','1');
            else
                main_win_num_str=[main_win_num_str,'3'];
                set(h_edit,'string',main_win_num_str);
            end
        else
            if main_win_num_str=='0'%如果当前的数为0,则先清空
                main_win_num_str='';
            end
            if length(main_win_num_str)>=14 %最大的操作数超过1e+14会出错
                errordlg({'友情提示:   操作数不能大于1e+14'},'error');
            end
            main_win_num_str=[main_win_num_str,'3'];
            set(h_edit,'string',main_win_num_str);
        end
    case 'num2'
        h_edit=findobj(0,'tag','MAIN_EDIT');
        h_num9=findobj(0,'tag','MAIN_BUT9');
        h_state=findobj(0,'tag','OPERATION_STATE');
        h_sequence=findobj(0,'tag','OPERATION_SEQUENCE');
        h_opert=findobj(0,'tag','OPERATOR_ONE');
        h_sequence_num=round(str2num(get(h_sequence,'string')));
        h_opert_num=round(str2num(get(h_state,'string')));
        main_win_num_str=get(h_edit,'string');
        if h_opert_num==1 | h_opert_num==2 | h_opert_num==3 | h_opert_num==4 %按此键之前按了运算符
            if h_sequence_num==0
                set(h_edit,'string','2');
                set(h_sequence,'string','1');
            else
                main_win_num_str=[main_win_num_str,'2'];
                set(h_edit,'string',main_win_num_str);
            end
        else
            if main_win_num_str=='0'%如果当前的数为0,则先清空
                main_win_num_str='';
            end
            if length(main_win_num_str)>=14 %最大的操作数超过1e+14会出错
                errordlg({'友情提示:   操作数不能大于1e+14'},'error');
            end
            main_win_num_str=[main_win_num_str,'2'];
            set(h_edit,'string',main_win_num_str);
        end
    case 'num1'
        h_edit=findobj(0,'tag','MAIN_EDIT');
        h_num9=findobj(0,'tag','MAIN_BUT9');
        h_state=findobj(0,'tag','OPERATION_STATE');
        h_sequence=findobj(0,'tag','OPERATION_SEQUENCE');
        h_opert=findobj(0,'tag','OPERATOR_ONE');
        h_sequence_num=round(str2num(get(h_sequence,'string')));
        h_opert_num=round(str2num(get(h_state,'string')));
        main_win_num_str=get(h_edit,'string');
        if h_opert_num==1 | h_opert_num==2 | h_opert_num==3 | h_opert_num==4 %按此键之前按了运算符
            if h_sequence_num==0
                set(h_edit,'string','1');
                set(h_sequence,'string','1');
            else
                main_win_num_str=[main_win_num_str,'1'];
                set(h_edit,'string',main_win_num_str);
            end
        else
            if main_win_num_str=='0'%如果当前的数为0,则先清空
                main_win_num_str='';
            end
            if length(main_win_num_str)>=14 %最大的操作数超过1e+14会出错
                errordlg({'友情提示:   操作数不能大于1e+14'},'error');
            end
            main_win_num_str=[main_win_num_str,'1'];
            set(h_edit,'string',main_win_num_str);
        end
    case 'num0'
        h_edit=findobj(0,'tag','MAIN_EDIT');
        h_num9=findobj(0,'tag','MAIN_BUT9');
        h_state=findobj(0,'tag','OPERATION_STATE');
        h_sequence=findobj(0,'tag','OPERATION_SEQUENCE');
        h_opert=findobj(0,'tag','OPERATOR_ONE');
        h_sequence_num=round(str2num(get(h_sequence,'string')));
        h_opert_num=round(str2num(get(h_state,'string')));
        main_win_num_str=get(h_edit,'string');
        if h_opert_num==1 | h_opert_num==2 | h_opert_num==3 | h_opert_num==4 %按此键之前按了运算符
            if h_sequence_num==0
                set(h_edit,'string','0');
                set(h_sequence,'string','1');
            else
                main_win_num_str=[main_win_num_str,'0'];
                set(h_edit,'string',main_win_num_str);
            end
        else
            if main_win_num_str=='0'%如果当前的数为0,则先清空
                main_win_num_str='';
            end
            if length(main_win_num_str)>=14 %最大的操作数超过1e+14会出错
                errordlg({'友情提示:   操作数不能大于1e+14'},'error');
            end
            main_win_num_str=[main_win_num_str,'0'];
            set(h_edit,'string',main_win_num_str);
        end
    case 'dots'
        flag=0;
        h_edit=findobj(0,'tag','MAIN_EDIT');
        h_dots=findobj(0,'tag','MAIN_DOTS');
        main_win_num_str=get(h_edit,'string');
        for k=1:length(main_win_num_str)%寻找当前的数中是否已有小数点
            if main_win_num_str(k)=='.'
                flag=1;
                break;
            end
        end
        if flag~=1
            main_win_num_str=[main_win_num_str,'.'];
            set(h_edit,'string',main_win_num_str);
        end
    case 'msqrt'
        h_edit=findobj(0,'tag','MAIN_EDIT');
        h_sqrt=findobj(0,'tag','MAIN_SQRT');
        main_win_num=round(str2num(get(h_edit,'string')));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -