在matlab中制作计算器

时间:2015-10-30 15:55:04

标签: matlab

我想在matlab中制作一个计算器......我创建了计算器的窗口,但现在我不知道如何取出插入的值并在我称之为result的文本字段中显示结果。

prompt={'Enter your numbers:','Result:'};
title='Calculator'; 
% The main title of your input dialog interface.
answer=inputdlg(prompt,title);
numbers = str2num(answer{1}); 
Result = getvalue(numbers);
% Convert these values to a number using str2num.

当我在numbers = str2num(answer{1});中输入并添加两个数字时,我的结果字段中没有得到结果... 我需要做些什么才能纠正代码以使其有效? 感谢

编辑:

prompt1={'Enter your numbers:','Result:'};
prompt2={'Enter your numbers:','Result:'};
% The main title of your input dialog interface.
answer=inputdlg(prompt1);
numbers = str2num(answer{1}); 
svar=outputdlg(prompt2);
Result = str2num(get(numbers).svar{1});
% Convert these values to a number using str2num.

1 个答案:

答案 0 :(得分:0)

我不确定你在这里想要达到的目标,但这可能会有所帮助:

main (){
    // Clear Buffer 
    buffer[nbytes] = '\0';  
    ...
    while(1);
    ...
}

编辑:要从同一个对话框中输入这两个数字,请尝试以下操作:

number1_str = inputdlg('Enter the first number:');
number2_str = inputdlg('Enter the second number:');

number1 = str2num(number1_str{1});
number2 = str2num(number2_str{1});

msgbox(sprintf('The result of %i + %i is %i', number1, number2, number1 + number2))