MATLAB GUI 界面 EDIT TEXT数组输入输出的问题
具体:A=[1 2 3 4 5],B=[2 3 4 5 6],第一个可编辑文本框读取A,第二个可编辑文本框读取B里面,设置一个按钮进行如下计算:A和B的各个元素对应相乘,对所有的乘积求和,再除以B数组中各个元素的和。对最后的结果通过text输出。应该如何操作?求大侠! 展开
建立GUI界面,设三个可编辑文本框Tag为A_edit,B_edit,O_edit,生成的M文件修改后部分如下:
function baidu1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has 指激no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles 仿手 structure with handles and user data (see GUIDATA)
% varargin command line arguments to baidu1 (see VARARGIN)
set(handles.A_edit,'String','');
set(handles.B_edit,'String','');
% Choose default command line output for baidu1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes baidu1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
function output_push_Callback(hObject, eventdata, handles)
% hObject handle to output_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
A=str2num(get(handles.A_edit,'String'备逗嫌));
B=str2num(get(handles.B_edit,'String'));
S=sum(A.*B)/sum(B);
set(handles.O_edit,'String',num2str(S));