0
나는이 방법matlab 함수를 만들었습니다. 입력은 수학 식과 매개 변수입니다. 내 기능을위한 GUI를 만들려면 어떻게해야합니까?
formula = @(a,b) a+b ;
내가 MATLAB 함수에 인수로 "공식을"사용에 수학 함수를 정의 :
function result = myfunction(formula,a,b)
result = formula(a,b);
end
모든 것이
formula = @(a,b) a+b ;
result=myfunction(formula,3,2)
result =
5
하지만 내를 잘 작동 목표는 GUI를 만드는 것이므로 다음을 시도했습니다.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
formula=get(handles.edit1,'String');
a=str2double(get(handles.edit2,'String'))
b=str2double(get(handles.edit3,'String'))
result = formula(a,b);
set(handles.text1,'string',result);
하지만 난이 오류 :
Index exceeds matrix dimensions.
Error in untitled>pushbutton1_Callback (line 86)
result = formula(a,b);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in untitled (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)untitled('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
어떻게 내 문제를 해결할 수 있습니까?
대단히 감사합니다. 내 문제를 해결해 주셔서 감사합니다. get (handles.edit1, 'String')])은 셀을 반환하므로 str2func() 전에 다음을 넣습니다. formula = formula {1}; 그리고 나서 : formula = str2func (formula); – xontas