MATLAB: I am getting an error Undefined operator ‘^’ for input arguments of type ‘matlab.ui​.control.U​IControl’. Error in sdpc>pushb​utton1_Cal​lback (line 159) handles.rp​=(handles.​h^2)/handl​es.mu/(1+h​andles.e); %in km i dont know why ?Request for hel

guidematlab functionmatlab gui

% code
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)
%e=get(handles.e,'value');
%e=str2num(e);
h=get(handles.h,'string');
set(handles.s1,'string',h);
h=str2double(h);
e=get(handles.e,'string');
set(handles.s2,'string',e);
e=str2double(e);
handles.mu=398600;
handles.rp=(handles.h^2)/handles.mu/(1+handles.e); %in km
handles.ra=(handles.h^2)/handles.mu/(1-handles.e); % in km

handles.a1=(handles.rp + handles.ra)/2; % in km
handles.T1 = 2*pi/sqrt(handles.mu)*(handles.a1)^(1.5); %in seconds
%set(handles.s3,'string',rp);
end

Best Answer

The inflationary usage of the struct handles is not valid in your code. As the error message tells clearly already, you cannot apply the power operator to the graphics handle stored in handle.h . But before you do this, you take care to get the string value of this handle and convert it to a number:
h = get(handles.h, 'string');
h = str2double(h);
Then I guess, you want to use "h" instead of "handles.h". A bold try to fix your code:
function pushbutton1_Callback(hObject, eventdata, handles)
hStr = get(handles.h, 'string');
set(handles.s1, 'string', hStr);
hNum = str2double(hStr);
eStr = get(handles.e, 'string');
set(handles.s2, 'string', eStr);
eNum = str2double(eStr);
handles.mu = 398600;
handles.rp = (hNum ^ 2) / handles.mu / (1 + eNum); %in km
handles.ra = (hNum ^ 2) / handles.mu / (1 - eNum); % in km

handles.a1 = (handles.rp + handles.ra) / 2; % in km
handles.T1 = 2 * pi / sqrt(handles.mu) * handles.a1 ^ 1.5; %in seconds
guidata(hObject, handles); % Store the updated handles struct
end
Related Question