下面是我要构建的gui的代码视图,其中包括一个地球模型。 我的目标是将其纳入Matlab的“ appdesigner”中。我尝试了多种方法使其工作,但我似乎无济于事。 在appdesigner代码中,这是我尝试过的。有很多额外的代码,但我关注的是“在选项卡1内创建“世界视图”图”。任何帮助将不胜感激。
classdef Trajectory_application < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
GamaminLabel matlab.ui.control.Label
GamaminEditField matlab.ui.control.NumericEditField
ProjectEditFieldLabel matlab.ui.control.Label
ProjectEditField matlab.ui.control.EditField
SelectRangeforVGamaLabel matlab.ui.control.Label
GamamaxLabel matlab.ui.control.Label
GamamaxEditField matlab.ui.control.NumericEditField
VelocityminLabel matlab.ui.control.Label
VelocityminEditField matlab.ui.control.NumericEditField
VelocitymaxLabel matlab.ui.control.Label
VelocitymaxEditField matlab.ui.control.NumericEditField
UIAxes matlab.ui.control.UIAxes
ENTERButton matlab.ui.control.Button
TabGroup matlab.ui.container.TabGroup
WorldViewTab matlab.ui.container.Tab
TrajectoryImpactTab matlab.ui.container.Tab
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Color = [0.9373 0.9373 0.9373];
app.UIFigure.Position = [100 100 694 661];
app.UIFigure.Name = 'UI Figure';
setAutoResize(app, app.UIFigure, true)
% Create GamaminLabel
app.GamaminLabel = uilabel(app.UIFigure);
app.GamaminLabel.HorizontalAlignment = 'right';
app.GamaminLabel.Position = [53 557 70 15];
app.GamaminLabel.Text = 'Gama (min): ';
% Create GamaminEditField
app.GamaminEditField = uieditfield(app.UIFigure, 'numeric');
app.GamaminEditField.Position = [129 553 100 22];
% Create ProjectEditFieldLabel
app.ProjectEditFieldLabel = uilabel(app.UIFigure);
app.ProjectEditFieldLabel.HorizontalAlignment = 'right';
app.ProjectEditFieldLabel.Position = [20 635 46 15];
app.ProjectEditFieldLabel.Text = 'Project:';
% Create ProjectEditField
app.ProjectEditField = uieditfield(app.UIFigure, 'text');
app.ProjectEditField.Position = [81 631 119 22];
app.ProjectEditField.Value = 'Trajectory Analysis';
% Create SelectRangeforVGamaLabel
app.SelectRangeforVGamaLabel = uilabel(app.UIFigure);
app.SelectRangeforVGamaLabel.FontAngle = 'italic';
app.SelectRangeforVGamaLabel.Position = [53 586 147 15];
app.SelectRangeforVGamaLabel.Text = 'Select Range for V-Gama:';
% Create GamamaxLabel
app.GamamaxLabel = uilabel(app.UIFigure);
app.GamamaxLabel.HorizontalAlignment = 'right';
app.GamamaxLabel.Position = [47 527 78 15];
app.GamamaxLabel.Text = 'Gama (max): ';
% Create GamamaxEditField
app.GamamaxEditField = uieditfield(app.UIFigure, 'numeric');
app.GamamaxEditField.Position = [130 523 99 22];
% Create VelocityminLabel
app.VelocityminLabel = uilabel(app.UIFigure);
app.VelocityminLabel.HorizontalAlignment = 'right';
app.VelocityminLabel.Position = [38 498 86 15];
app.VelocityminLabel.Text = 'Velocity (min): ';
% Create VelocityminEditField
app.VelocityminEditField = uieditfield(app.UIFigure, 'numeric');
app.VelocityminEditField.Position = [129 494 100 22];
% Create VelocitymaxLabel
app.VelocitymaxLabel = uilabel(app.UIFigure);
app.VelocitymaxLabel.HorizontalAlignment = 'right';
app.VelocitymaxLabel.Position = [37 469 88 15];
app.VelocitymaxLabel.Text = 'Velocity (max): ';
% Create VelocitymaxEditField
app.VelocitymaxEditField = uieditfield(app.UIFigure, 'numeric');
app.VelocitymaxEditField.Position = [130 465 100 22];
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'V-Gama at Re-entry');
xlabel(app.UIAxes, 'GAMA (deg)');
ylabel(app.UIAxes, 'Velocity (mps)');
app.UIAxes.Box = 'on';
app.UIAxes.XGrid = 'on';
app.UIAxes.YGrid = 'on';
app.UIAxes.Position = [291 408 381 245];
% Create ENTERButton
app.ENTERButton = uibutton(app.UIFigure, 'push');
app.ENTERButton.Position = [107 408 100 22];
app.ENTERButton.Text = 'ENTER';
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [65 13 566 380];
% Create WorldViewTab
app.WorldViewTab = uitab(app.TabGroup);
app.WorldViewTab.Title = 'World View';
app.WorldViewTab.BackgroundColor = [0.302 0.2863 0.2863];
app.WorldViewTab.Units = 'pixels';
% Create TrajectoryImpactTab
app.TrajectoryImpactTab = uitab(app.TabGroup);
app.TrajectoryImpactTab.Title = 'Trajectory Impact';
app.TrajectoryImpactTab.BackgroundColor = [0.9373 0.9373 0.9373];
app.TrajectoryImpactTab.Units = 'pixels';
% Create Plot within tab 2
gx = geoaxes(app.TrajectoryImpactTab);
gx.Title = 'Initial lat / long of Trajectory';
gx.Position = [92 52 381 245];
geoplot(gx,latTraj,lonTraj);
% Create 'World View' Plot within tab 1
wv = uiaxes(app.WorldViewTab);
wv.Position = [92 52 381 245];
earth_sphere(wv, gca, 'm');
end
end
methods (Access = public)
% Construct app
function app = Trajectory_application()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
%% Earth-build Function
function [xx,yy,zz] = earth_sphere(varargin)
% EARTH_SPHERE(N,'mile') graphs the earth with miles as the unit rather
% than kilometers. Other valid inputs are 'ft' 'm' 'nm' 'miles' and 'AU'
% for feet, meters, nautical miles, miles, and astronomical units
% respectively.
%
% EARTH_SPHERE(AX,...) plots into AX instead of GCA.
%% Input Handling
[cax,args,nargs] = axescheck(varargin{:}); % Parse possible Axes input
error(nargchk(0,2,nargs)); % Ensure there are a valid number of inputs
j = 0;
k = 0;
n = 50; % default value
units = 'km'; % default value
for i = 1:nargs
if ischar(args{i})
units = args{i};
j = j+1;
elseif isnumeric(args{i})
n = args{i};
k = k+1;
end
end
if j > 1 || k > 1
error('Invalid input types')
end
%% Calculations
% Scale factors
Scale = {'km' 'm' 'mile' 'miles' 'nm' 'au' 'ft';
1 1000 0.621371192237334 0.621371192237334 0.539956803455724 6.6845871226706e-009 3280.839895};
% Identify which scale to use
try
myscale = 6378.1363*Scale{2,strcmpi(Scale(1,:),units)};
catch %#ok<*CTCH>
error('Invalid units requested. Please use m, km, ft, mile, miles, nm, or AU')
end
% -pi <= theta <= pi is a row vector.
% -pi/2 <= phi <= pi/2 is a column vector.
theta = (-n:2:n)/n*pi;
phi = (-n:2:n)'/n*pi/2;
cosphi = cos(phi); cosphi(1) = 0; cosphi(n+1) = 0;
sintheta = sin(theta); sintheta(1) = 0; sintheta(n+1) = 0;
x = myscale*cosphi*cos(theta);
y = myscale*cosphi*sintheta;
z = myscale*sin(phi)*ones(1,n+1);
%% Plotting
if nargout == 0
cax = newplot(cax);
% Load and define topographic data
load('topo.mat','topo','topomap1');
% Rotate data to be consistent with the Earth-Centered-Earth-Fixed
% coordinate conventions. X axis goes through the prime meridian.
% http://en.wikipedia.org/wiki/Geodetic_system#Earth_Centred_Earth_Fixed_.28ECEF_or_ECF.29_coordinates
%
% Note that if you plot orbit trajectories in the Earth-Centered-
% Inertial, the orientation of the contintents will be misleading.
topo2 = [topo(:,181:360) topo(:,1:180)]; %#ok<NODEF>
% Define surface settings
props.FaceColor= 'texture';
props.EdgeColor = 'none';
props.FaceLighting = 'phong';
props.Cdata = topo2;
% Create the sphere with Earth topography and adjust colormap
surface(x,y,z,props,'parent',cax)
colormap(topomap1)
% Replace the calls to surface and colormap with these lines if you do
% not want the Earth's topography displayed.
% surf(x,y,z,'parent',cax)
% shading flat
% colormap gray
% Refine figure
axis equal
xlabel(['X [' units ']'])
ylabel(['Y [' units ']'])
zlabel(['Z [' units ']'])
view(127.5,30)
else
xx = x; yy = y; zz = z;
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
结束