Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
46 views

Coordinate Conversion Using Matlab Gui

This document describes the code for a GUI called cartospherical. It contains functions for creating the cartospherical figure, handling callbacks and outputs. The code takes Cartesian coordinates as input in three edit boxes, calculates spherical coordinates, and displays the results in three output edit boxes. It also includes generic callback and creation functions for GUI components like edit boxes and listboxes.

Uploaded by

Oral Robertz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Coordinate Conversion Using Matlab Gui

This document describes the code for a GUI called cartospherical. It contains functions for creating the cartospherical figure, handling callbacks and outputs. The code takes Cartesian coordinates as input in three edit boxes, calculates spherical coordinates, and displays the results in three output edit boxes. It also includes generic callback and creation functions for GUI components like edit boxes and listboxes.

Uploaded by

Oral Robertz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

function varargout = cartospherical(varargin)

% CARTOSPHERICAL MATLAB code for cartospherical.fig


% CARTOSPHERICAL, by itself, creates a new
CARTOSPHERICAL or raises the existing
% singleton*.
%
% H = CARTOSPHERICAL returns the handle to a new
CARTOSPHERICAL or the handle to
% the existing singleton*.
%
%
CARTOSPHERICAL('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in CARTOSPHERICAL.M with the
given input arguments.
%
% CARTOSPHERICAL('Property','Value',...) creates a new
CARTOSPHERICAL or raises the
% existing singleton*. Starting from the left,
property value pairs are
% applied to the GUI before cartospherical_OpeningFcn
gets called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to
cartospherical_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI
allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help


cartospherical

% Last Modified by GUIDE v2.5 11-Feb-2021 14:59:15

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@cartospherical_OpeningFcn, ...
'gui_OutputFcn',
@cartospherical_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State,
varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before cartospherical is made visible.


function cartospherical_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 cartospherical (see
VARARGIN)

% Choose default command line output for cartospherical


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes cartospherical wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = cartospherical_OutputFcn(hObject,
eventdata, handles)
% varargout cell array for returning output args (see
VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (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 edit1 as


text
% str2double(get(hObject,'String')) returns contents
of edit1 as a double

% --- Executes during object creation, after setting all


properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: edit controls usually have a white background on


Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as


text
% str2double(get(hObject,'String')) returns contents
of edit2 as a double

% --- Executes during object creation, after setting all


properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: edit controls usually have a white background on


Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (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 edit3 as


text
% str2double(get(hObject,'String')) returns contents
of edit3 as a double
% --- Executes during object creation, after setting all
properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: edit controls usually have a white background on


Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- 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)
x1= get(handles.edit1,'string');
x= str2num(x1);
y1 = get(handles.edit2,'string');
y = str2num(y1);
z1 = get(handles.edit3,'string');
z = str2num(z1);
r = sqrt((x^2)+(y^2)+(z^2));
theta = acosd(z./(sqrt((x^2)+(y^2)+(z^2))));
if (x<0 || y<0)|| (x && y <0)

phi = atand(y./x)+180;

else
phi = atand(y./x);
end
set(handles.edit4,'string',num2str(r));
set(handles.edit5,'string',num2str(theta));
set(handles.edit6,'string',num2str(phi));

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (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 edit4 as


text
% str2double(get(hObject,'String')) returns contents
of edit4 as a double

% --- Executes during object creation, after setting all


properties.
function edit4_CreateFcn(hObject, ~, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: edit controls usually have a white background on


Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as


text
% str2double(get(hObject,'String')) returns contents
of edit5 as a double

% --- Executes during object creation, after setting all


properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: edit controls usually have a white background on


Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as


text
% str2double(get(hObject,'String')) returns contents
of edit6 as a double

% --- Executes during object creation, after setting all


properties.
function edit6_CreateFcn(hObject, ~, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called
% Hint: edit controls usually have a white background on
Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in listbox3.


function listbox3_Callback(hObject, eventdata, handles)
% hObject handle to listbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns


listbox3 contents as cell array
% contents{get(hObject,'Value')} returns selected
item from listbox3

% --- Executes during object creation, after setting all


properties.
function listbox3_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: listbox controls usually have a white background on


Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in popupmenu2.


function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns


popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected
item from popupmenu2

% --- Executes during object creation, after setting all


properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: popupmenu controls usually have a white background


on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
set(handles.edit1,'string',"");
set(handles.edit2,'string',"");
set(handles.edit3,'string',"");
set(handles.edit4,'string',"");
set(handles.edit5,'string',"");
set(handles.edit6,'string',"");

You might also like