Calculator by matlab sin, cos, tan

조회 수: 9 (최근 30일)
Gry
Gry 2014년 10월 23일
댓글: Walter Roberson 2019년 12월 4일
Hi I have made a new GUI in matlab for a calculator. The calculator is fully working exept there is an error with the sin, cos and tan buttons. If i click one of them i get this error:
Error in @(hObject,eventdata)calculator('pushbutton13_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I think i made an error in the pushbutton code, just not sure whats the error
I have attached the m file for the calculator pluss the figure.

채택된 답변

David Sanchez
David Sanchez 2014년 10월 23일
You wrote the sin. cos and tan funcitons beggining with with capital letters:
Sin, Cos and Tan in your code.
Write the functions like this:
% --- Executes on button press in Tan.
function Tan_Callback(hObject, eventdata, handles)
% hObject handle to Tan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
textstring = get(handles.text1,'string');
textstring = strcat(textstring,'tan')
set(handles.text1,'string',textstring);
% --- 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)
textstring = get(handles.text1,'string');
textstring = strcat(textstring,'sin')
set(handles.text1,'string',textstring);
% --- 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)
textstring = get(handles.text1,'string');
textstring = strcat(textstring,'cos')
set(handles.text1,'string',textstring);
  댓글 수: 2
Gry
Gry 2014년 10월 23일
Thank you so much!
Really appreciate it
David Sanchez
David Sanchez 2014년 10월 23일
accept the answer then, thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

James Berryman
James Berryman 2019년 12월 4일
how would I use MATLAB to find tan2x − sec2x.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 12월 4일
f1 = @(x) tan(2*x) - sec(2*x)
f2 = @(x) tan(x).^2 - sec(x).^2
and call f1(x) or f2(x) depending which of the two meanings you intended.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by