Question: When calculating a trigonometric function using Matlab GUI, for example, if I press the 7 button, press the sin button, press the + button, press

When calculating a trigonometric function using Matlab GUI, for example, if I press the 7 button, press the sin button, press the + button, press the 6 button, and press the cos button, i want to calculate it as sin(7)+cos(6), but It is calculated like
cos( sin(7)+6).
function btn_equation_Callback(hObject, eventdata, handles)
% hObject handle to btn_eq (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
v=get(handles.etxt_LCD,'String');
total=eval(v);
set(handles.etxt_LCD,'String',[v,'=',num2str(total)])
current_expression = get(handles.etxt_LCD, 'String');
try
result = eval(replace(current_expression, 'sin', 'sind'));
set(handles.etxt_LCD, 'String', num2str(result));
end
function btn_sin_Callback(hObject, eventdata, handles)
% hObject handle to btn_sin (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 btn_sin as text
% str2double(get(hObject,'String')) returns contents of btn_sin as a double
current_value = get(handles.etxt_LCD, 'String');
output_str =['sin(', current_value, ')'];
set(handles.etxt_LCD, 'String', output_str);
guidata(hObject, handles);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!