Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2008-04-18, 12:56   #1
andy1011
初级会员
 
注册日期: 2008-04-18
年龄: 39
帖子: 1
声望力: 0
andy1011 正向着好的方向发展
默认 [求助]好心的帅哥美女 小弟急啊 帮帮忙

小弟跪求高手帮忙
本人要完成一个作业,完成一个计算器,程序已经编好 但是有点小错误
[email protected]
引用:
function varargout = calculator(varargin)
% 我的计算器,重要运用了文本框和按钮。

gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @calculator_OpeningFcn, ...
'gui_OutputFcn', @calculator_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end

function calculator_OpeningFcn(hObject, eventdata, handles, varargin)

handles.current_str='';%此为存储当前的字符串。

% Choose default command line output for calculator
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes calculator wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = calculator_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)

%连接当前的字符串和1,如果按了1键的话。
handles.current_str=strcat(handles.current_str,'1');
%在输出当前的字符串
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'2');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'3');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'4');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'5');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'6');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'7');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'8');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'9');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'0');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)



function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end





function add_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'+');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in plus.
function plus_Callback(hObject, eventdata, handles)


handles.current_str=strcat(handles.current_str,'-');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);
% --- Executes on button press in chen.
function chen_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'*');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);
% --- Executes on button press in chu.
function chu_Callback(hObject, eventdata, handles)

handles.current_str=strcat(handles.current_str,'/');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);


% --- Executes on button press in log.
function log_Callback(hObject, eventdata, handles)
% hObject handle to log (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.current_str=strcat(handles.current_str,'log');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in sin.
function sin_Callback(hObject, eventdata, handles)
% hObject handle to sin (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.current_str=strcat(handles.current_str,'sin');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);

% --- Executes on button press in cos.
function cos_Callback(hObject, eventdata, handles)
% hObject handle to cos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.current_str=strcat(handles.current_str,'cos');
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);


% --- Executes on button press in clo.
function clo_Callback(hObject, eventdata, handles)
close(gcf);


function guining_Callback(hObject, eventdata, handles)
%讲所有的字符串归零。
handles.current_str = '';
set(handles.edit1,'String','');
set(handles.edit2,'String','0');
guidata(hObject, handles);

function xiao_Callback(hObject, eventdata, handles)
handles.current_str=strcat(handles.current_str,'.');
guidata(hObject, handles);

%小数点
function result_Callback(hObject, eventdata, handles)

st = get(handles.edit1,'String');
%计算结果,并存放到第二个编辑框中。
val = eval(st);
s = num2str(val);
set(handles.edit2,'String',s);

guidata(hObject, handles);




function xiao_ButtonDownFcn(hObject, eventdata, handles)





% --- Executes on button press in dele.
function dele_Callback(hObject, eventdata, handles)
% hObject handle to dele (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s1 = handles.current_str;
handles.current_str = s1(1:length(s1)-1);
set(handles.edit1,'String',handles.current_str);
guidata(hObject, handles);



% --------------------------------------------------------------------
function menu1_Callback(hObject, eventdata, handles)
% hObject handle to menu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

close(gcf);
% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)




% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_4_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_3_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_5_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)




:cry: :cry: 帮帮忙改下,log,sin,cos 都没有结果输出的
andy1011 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码


相似的主题
主题 主题作者 版面 回复 最后发表
【求助】今已接触matlab一个月了,共有19个问题,请前辈们多多指教! xfbg0303 MATLAB论坛 9 2012-09-09 19:58
[求助]knnclassify处理海量数据问题 iwwibyts MATLAB论坛 0 2008-04-24 20:54


所有时间均为北京时间。现在的时间是 09:35


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.