I want programming (Button pushed function: CSTButton) App design

Code
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Toolbar matlab.ui.container.Toolbar
PushTool matlab.ui.container.toolbar.PushTool
x5 matlab.ui.control.NumericEditField
y5 matlab.ui.control.NumericEditField
y4 matlab.ui.control.NumericEditField
x4 matlab.ui.control.NumericEditField
y3 matlab.ui.control.NumericEditField
y2 matlab.ui.control.NumericEditField
x3 matlab.ui.control.NumericEditField
x2 matlab.ui.control.NumericEditField
x1 matlab.ui.control.NumericEditField
y1 matlab.ui.control.NumericEditField
DimensionPropertyLabel matlab.ui.control.Label
PhaseLabel matlab.ui.control.Label
ElementDataLabel matlab.ui.control.Label
CSTButton matlab.ui.control.Button
PreviewButton matlab.ui.control.Button
PhaseReference matlab.ui.control.NumericEditField
PhaseReferenceEditFieldLabel matlab.ui.control.Label
UnitElementDimensionsLabel matlab.ui.control.Label
Y matlab.ui.control.NumericEditField
YEditFieldLabel matlab.ui.control.Label
X matlab.ui.control.NumericEditField
XEditFieldLabel matlab.ui.control.Label
BeamDirectionLabel matlab.ui.control.Label
Azimuth matlab.ui.control.NumericEditField
AzimuthEditFieldLabel matlab.ui.control.Label
Elevation matlab.ui.control.NumericEditField
ElevationEditFieldLabel matlab.ui.control.Label
PhaseCenterCoordinates matlab.ui.control.Label
z matlab.ui.control.NumericEditField
zEditFieldLabel matlab.ui.control.Label
y matlab.ui.control.NumericEditField
yEditFieldLabel matlab.ui.control.Label
x matlab.ui.control.NumericEditField
xEditFieldLabel matlab.ui.control.Label
Image matlab.ui.control.Image
Frequency matlab.ui.control.NumericEditField
FrequencyGHzLabel matlab.ui.control.Label
Antennaradius matlab.ui.control.NumericEditField
AntennaradiusmmLabel matlab.ui.control.Label
DesignAReflectArrayLabel matlab.ui.control.Label
UIAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: CSTButton
function CSTButtonPushed(app, event)
end
% Value changed function: Antennaradius, Frequency
function AntennaradiusEditFieldValueChanged(app, event)
value = app.Antennaradius.Value
end
% Button pushed function: PreviewButton
function PreviewButtonPushed(app, event)
% Create GUIDE-style callback args - Added by Migration Tool
[hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
% 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)
handles = guidata(hObject);
% Frequency
freq = app.Frequency.Value * 10^9;
lambda = physconst('LightSpeed') * 1000 / freq;
k = 2 * pi / lambda;
ix = 1;
iy = 1;
% Sample data (Replace with actual data assignment)
data = [app.x1.Value app.y1.Value; app.x2.Value app.y2.Value; app.x3.Value app.y3.Value; app.x4.Value app.y5.Value ; app.x5.Value app.y5.Value];
phas_u = data(:,1)';
dim_u = data(:,2)';
the_dir = app.Elevation.Value;
phi_dir = app.Azimuth.Value;
pha_zer = app.PhaseReference.Value;
x_cor = app.x.Value;
y_cor = app.y.Value;
z_cor = app.z.Value;
rad = app.Antennaradius.Value;
uedimx = app.X.Value;
uedimy = app.Y.Value;
% Initialize phase array
phase = zeros(round(rad/uedimx), round(rad/uedimy));
for xi = -rad/2+mod(rad/2,uedimx):uedimx:rad/2
for yi = -rad/2+mod(rad/2,uedimy):uedimy:rad/2
if sqrt(xi^2+yi^2) < rad/2
R = sqrt((x_cor-xi)^2 + (y_cor-yi)^2 + z_cor^2);
phase(ix, iy) = k * (R - sind(the_dir) * (xi * cosd(phi_dir) + yi * sind(phi_dir))) + pha_zer;
m_phase = mod(phase(ix, iy), 2*pi);
m_phase_deg = m_phase * 180 / pi - 180;
if m_phase_deg > phas_u(1,1)
phas_lin_map = phas_u(1,1);
elseif m_phase_deg < phas_u(1,end)
phas_lin_map = phas_u(end,1);
else
dy = diff([0 phas_u]);
dyix = find(dy == 0);
dim_u(dyix) = dim_u(dyix-1) + 1E-8;
phas_lin_map = interp1(phas_u, dim_u, m_phase_deg);
end
else
phase(ix, iy) = 0;
end
iy = iy + 1;
end
ix = ix + 1;
iy = 1;
end
% Convert to degrees
m_phase = mod(phase, 2*pi);
m_phase_deg = m_phase * 180 / pi;
% Debugging
disp('Phase (degrees):');
disp(m_phase_deg);
% Plotting
surf(app.UIAxes, m_phase_deg);
view(app.UIAxes, 2);
guidata(hObject, handles);
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
delete(app)
end
% Value changed function: y1
function y1ValueChanged(app, event)
value = app.y1.Value;
end
% Value changed function: Elevation
function ElevationValueChanged(app, event)
value = app.Elevation.Value;
end
% Value changed function: Azimuth
function AzimuthValueChanged(app, event)
value = app.Azimuth.Value;
end
% Value changed function: X
function XValueChanged(app, event)
value = app.X.Value;
end
% Value changed function: Y
function YValueChanged(app, event)
value = app.Y.Value;
end
% Value changed function: PhaseReference
function PhaseReferenceValueChanged(app, event)
value = app.PhaseReference.Value;
end
% Button down function: UIAxes
function UIAxesButtonDown(app, event)
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Get the file path for locating images
pathToMLAPP = fileparts(mfilename('fullpath'));
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Color = [0.502 0.502 0.502];
app.UIFigure.Position = [100 100 984 624];
app.UIFigure.Name = 'MATLAB App';
app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);
% Create Toolbar
app.Toolbar = uitoolbar(app.UIFigure);
% Create PushTool
app.PushTool = uipushtool(app.Toolbar);
app.PushTool.Icon = fullfile(pathToMLAPP, 'images.png');
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
zlabel(app.UIAxes, 'Z')
app.UIAxes.ButtonDownFcn = createCallbackFcn(app, @UIAxesButtonDown, true);
app.UIAxes.Position = [582 331 346 269];
% Create DesignAReflectArrayLabel
app.DesignAReflectArrayLabel = uilabel(app.UIFigure);
app.DesignAReflectArrayLabel.HorizontalAlignment = 'center';
app.DesignAReflectArrayLabel.FontSize = 24;
app.DesignAReflectArrayLabel.FontWeight = 'bold';
app.DesignAReflectArrayLabel.FontAngle = 'italic';
app.DesignAReflectArrayLabel.Position = [363 593 272 32];
app.DesignAReflectArrayLabel.Text = 'Design A Reflect Array ';
% Create AntennaradiusmmLabel
app.AntennaradiusmmLabel = uilabel(app.UIFigure);
app.AntennaradiusmmLabel.HorizontalAlignment = 'center';
app.AntennaradiusmmLabel.Position = [22 553 117 30];
app.AntennaradiusmmLabel.Text = 'Antenna radius';
% Create Antennaradius
app.Antennaradius = uieditfield(app.UIFigure, 'numeric');
app.Antennaradius.ValueChangedFcn = createCallbackFcn(app, @AntennaradiusEditFieldValueChanged, true);
app.Antennaradius.Position = [169 557 77 22];
% Create FrequencyGHzLabel
app.FrequencyGHzLabel = uilabel(app.UIFigure);
app.FrequencyGHzLabel.HorizontalAlignment = 'right';
app.FrequencyGHzLabel.Position = [29 514 100 30];
app.FrequencyGHzLabel.Text = 'Frequency';
% Create Frequency
app.Frequency = uieditfield(app.UIFigure, 'numeric');
app.Frequency.RoundFractionalValues = 'on';
app.Frequency.ValueChangedFcn = createCallbackFcn(app, @AntennaradiusEditFieldValueChanged, true);
app.Frequency.Position = [169 518 77 20];
% Create Image
app.Image = uiimage(app.UIFigure);
app.Image.Position = [221 365 370 219];
app.Image.ImageSource = fullfile(pathToMLAPP, 'images.png');
% Create xEditFieldLabel
app.xEditFieldLabel = uilabel(app.UIFigure);
app.xEditFieldLabel.HorizontalAlignment = 'right';
app.xEditFieldLabel.Position = [30 447 25 22];
app.xEditFieldLabel.Text = 'x';
% Create x
app.x = uieditfield(app.UIFigure, 'numeric');
app.x.Position = [70 447 100 22];
% Create yEditFieldLabel
app.yEditFieldLabel = uilabel(app.UIFigure);
app.yEditFieldLabel.HorizontalAlignment = 'right';
app.yEditFieldLabel.Position = [30 402 25 22];
app.yEditFieldLabel.Text = 'y';
% Create y
app.y = uieditfield(app.UIFigure, 'numeric');
app.y.Position = [70 402 100 22];
% Create zEditFieldLabel
app.zEditFieldLabel = uilabel(app.UIFigure);
app.zEditFieldLabel.HorizontalAlignment = 'right';
app.zEditFieldLabel.Position = [30 360 25 22];
app.zEditFieldLabel.Text = 'z';
% Create z
app.z = uieditfield(app.UIFigure, 'numeric');
app.z.Position = [70 360 100 22];
% Create PhaseCenterCoordinates
app.PhaseCenterCoordinates = uilabel(app.UIFigure);
app.PhaseCenterCoordinates.FontSize = 14;
app.PhaseCenterCoordinates.Position = [22 489 170 22];
app.PhaseCenterCoordinates.Text = 'Phase Center Coordinates';
% Create ElevationEditFieldLabel
app.ElevationEditFieldLabel = uilabel(app.UIFigure);
app.ElevationEditFieldLabel.HorizontalAlignment = 'right';
app.ElevationEditFieldLabel.Position = [15 285 54 22];
app.ElevationEditFieldLabel.Text = 'Elevation';
% Create Elevation
app.Elevation = uieditfield(app.UIFigure, 'numeric');
app.Elevation.ValueChangedFcn = createCallbackFcn(app, @ElevationValueChanged, true);
app.Elevation.Position = [84 285 64 22];
% Create AzimuthEditFieldLabel
app.AzimuthEditFieldLabel = uilabel(app.UIFigure);
app.AzimuthEditFieldLabel.HorizontalAlignment = 'right';
app.AzimuthEditFieldLabel.Position = [15 255 48 22];
app.AzimuthEditFieldLabel.Text = 'Azimuth';
% Create Azimuth
app.Azimuth = uieditfield(app.UIFigure, 'numeric');
app.Azimuth.ValueChangedFcn = createCallbackFcn(app, @AzimuthValueChanged, true);
app.Azimuth.Position = [84 255 64 22];
% Create BeamDirectionLabel
app.BeamDirectionLabel = uilabel(app.UIFigure);
app.BeamDirectionLabel.FontSize = 14;
app.BeamDirectionLabel.Position = [10 321 101 22];
app.BeamDirectionLabel.Text = 'Beam Direction';
% Create XEditFieldLabel
app.XEditFieldLabel = uilabel(app.UIFigure);
app.XEditFieldLabel.HorizontalAlignment = 'right';
app.XEditFieldLabel.Position = [31 174 25 22];
app.XEditFieldLabel.Text = 'X';
% Create X
app.X = uieditfield(app.UIFigure, 'numeric');
app.X.ValueChangedFcn = createCallbackFcn(app, @XValueChanged, true);
app.X.Position = [71 174 98 22];
% Create YEditFieldLabel
app.YEditFieldLabel = uilabel(app.UIFigure);
app.YEditFieldLabel.HorizontalAlignment = 'right';
app.YEditFieldLabel.Position = [29 126 25 22];
app.YEditFieldLabel.Text = 'Y';
% Create Y
app.Y = uieditfield(app.UIFigure, 'numeric');
app.Y.ValueChangedFcn = createCallbackFcn(app, @YValueChanged, true);
app.Y.Position = [69 126 100 22];
% Create UnitElementDimensionsLabel
app.UnitElementDimensionsLabel = uilabel(app.UIFigure);
app.UnitElementDimensionsLabel.FontSize = 14;
app.UnitElementDimensionsLabel.Position = [15 216 162 22];
app.UnitElementDimensionsLabel.Text = 'Unit Element Dimensions';
% Create PhaseReferenceEditFieldLabel
app.PhaseReferenceEditFieldLabel = uilabel(app.UIFigure);
app.PhaseReferenceEditFieldLabel.HorizontalAlignment = 'right';
app.PhaseReferenceEditFieldLabel.Position = [9 83 98 22];
app.PhaseReferenceEditFieldLabel.Text = 'Phase Reference';
% Create PhaseReference
app.PhaseReference = uieditfield(app.UIFigure, 'numeric');
app.PhaseReference.ValueChangedFcn = createCallbackFcn(app, @PhaseReferenceValueChanged, true);
app.PhaseReference.Position = [130 83 58 22];
% Create PreviewButton
app.PreviewButton = uibutton(app.UIFigure, 'push');
app.PreviewButton.ButtonPushedFcn = createCallbackFcn(app, @PreviewButtonPushed, true);
app.PreviewButton.FontSize = 14;
app.PreviewButton.Position = [731 250 110 25];
app.PreviewButton.Text = 'Preview';
% Create CSTButton
app.CSTButton = uibutton(app.UIFigure, 'push');
app.CSTButton.ButtonPushedFcn = createCallbackFcn(app, @CSTButtonPushed, true);
app.CSTButton.FontSize = 14;
app.CSTButton.Position = [731 160 110 25];
app.CSTButton.Text = ' CST';
% Create ElementDataLabel
app.ElementDataLabel = uilabel(app.UIFigure);
app.ElementDataLabel.FontSize = 14;
app.ElementDataLabel.Position = [320 310 142 27];
app.ElementDataLabel.Text = 'Element Data';
% Create PhaseLabel
app.PhaseLabel = uilabel(app.UIFigure);
app.PhaseLabel.Position = [326 281 39 22];
app.PhaseLabel.Text = 'Phase';
% Create DimensionPropertyLabel
app.DimensionPropertyLabel = uilabel(app.UIFigure);
app.DimensionPropertyLabel.Position = [461 276 110 22];
app.DimensionPropertyLabel.Text = 'Dimension/Property';
% Create y1
app.y1 = uieditfield(app.UIFigure, 'numeric');
app.y1.ValueChangedFcn = createCallbackFcn(app, @y1ValueChanged, true);
app.y1.Position = [461 242 100 22];
% Create x1
app.x1 = uieditfield(app.UIFigure, 'numeric');
app.x1.Position = [321 243 100 22];
% Create x2
app.x2 = uieditfield(app.UIFigure, 'numeric');
app.x2.Position = [321 203 100 22];
% Create x3
app.x3 = uieditfield(app.UIFigure, 'numeric');
app.x3.Position = [321 161 100 22];
% Create y2
app.y2 = uieditfield(app.UIFigure, 'numeric');
app.y2.Position = [461 203 100 22];
% Create y3
app.y3 = uieditfield(app.UIFigure, 'numeric');
app.y3.Position = [461 163 100 22];
% Create x4
app.x4 = uieditfield(app.UIFigure, 'numeric');
app.x4.Position = [321 123 100 22];
% Create y4
app.y4 = uieditfield(app.UIFigure, 'numeric');
app.y4.Position = [460 123 100 22];
% Create y5
app.y5 = uieditfield(app.UIFigure, 'numeric');
app.y5.Position = [461 83 100 22];
% Create x5
app.x5 = uieditfield(app.UIFigure, 'numeric');
app.x5.Position = [321 82 100 22];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
I want programming (Button pushed function: CSTButton)
Connect Matlab to cst studio

Réponses (0)

Catégories

Question posée :

il y a environ 14 heures

Commenté :

il y a environ 12 heures

Community Treasure Hunt

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

Start Hunting!

Translated by