after input values and push preview doesn’t display in UIAxes
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
EditField3_5 matlab.ui.control.NumericEditField
EditField2_5 matlab.ui.control.NumericEditField
EditField2_4 matlab.ui.control.NumericEditField
EditField3_4 matlab.ui.control.NumericEditField
EditField2_3 matlab.ui.control.NumericEditField
EditField2_2 matlab.ui.control.NumericEditField
EditField3_3 matlab.ui.control.NumericEditField
EditField3_2 matlab.ui.control.NumericEditField
EditField3 matlab.ui.control.NumericEditField
EditField2 matlab.ui.control.NumericEditField
DimensionPrpertyLabel matlab.ui.control.Label
PhaseLabel matlab.ui.control.Label
ElementDataLabel matlab.ui.control.Label
DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel 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
FrequencyEditFieldLabel matlab.ui.control.Label
Antennaradius matlab.ui.control.NumericEditField
AntennaradiusEditFieldLabel 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)
% — Executes on button press in pushbutton2.
% Create GUIDE-style callback args – Added by Migration Tool
[hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
% 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)
handles = guidata(hObject);
addpath(genpath(‘C:UsersseymurDesktopcst-matlabCST-MATLAB-API-master’));
cst = actxserver(‘CSTStudio.application’);
mws = cst.invoke(‘NewMWS’);
cst = actxserver(‘CSTStudio.Application’);
mws = cst.OpenFile(‘path_to_your_cst_file.cst’);
fmin=2.2;
fmax=2.6;
function CstDefineFrequencyRange(mws, startFreq, endFreq)
mws.invoke(‘FrequencyRange’, ‘Define’, startFreq, endFreq);
end
mws = cst.invoke(‘NewMWS’);
Xmin=’expanded open’;
Xmax=’expanded open’;
Ymin=’expanded open’;
Ymax=’expanded open’;
Zmin=’expanded open’;
Zmax=’expanded open’;
minfrequency = fmin;
function CstDefineOpenBoundary(mws, minfrequency, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax)
% CstDefineOpenBoundary – Defines the open boundary in CST.
%
% Inputs:
% mws – CST Microwave Studio object
% minfrequency – Minimum frequency for the boundary
% Xmin, Xmax, Ymin, Ymax, Zmin, Zmax – Boundary limits in each direction
% Assuming CST’s boundary settings are being configured using invoke calls
invoke(mws, ‘Boundary’, ‘Define’, ‘Xmin’, Xmin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Xmax’, Xmax);
invoke(mws, ‘Boundary’, ‘Define’, ‘Ymin’, Ymin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Ymax’, Ymax);
invoke(mws, ‘Boundary’, ‘Define’, ‘Zmin’, Zmin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Zmax’, Zmax);
% Set minimum frequency (this part may vary depending on how CST handles this)
invoke(mws, ‘Solver’, ‘FrequencyRange’, minfrequency);
end
freq = app.Frequency.Value * 10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
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;
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;
% phas_lin_map=m_phase_deg*m+n;
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
m_phase=mod(phase,2*pi);
m_phase_deg=m_phase*180/pi;
m_phase_deg(:);
surf(app.UIAxes, m_phase_deg);
view(app.UIAxes, 2);
surf(m_phase_deg)
view(2)
guidata(hObject, handles);
end
% Value changed function: Antennaradius, Frequency
function AntennaradiusEditFieldValueChanged(app, event)
value = app.Antennaradius.Value;
end
% Button pushed function: PreviewButton
function PreviewButtonPushed(app, event)
% 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 = [140 0.2; 130 1.5; 0 2.5; -150 3.5; -175 4.5];
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
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
delete(app)
end
% Value changed function: EditField2
function EditField2ValueChanged(app, event)
value = app.EditField2.Value;
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);
app.UIAxes.XColor = [0 0 0];
app.UIAxes.Position = [602 321 329 262];
% Create DesignareflectarrayLabel
app.DesignareflectarrayLabel = uilabel(app.UIFigure);
app.DesignareflectarrayLabel.FontSize = 24;
app.DesignareflectarrayLabel.FontWeight = ‘bold’;
app.DesignareflectarrayLabel.Position = [363 593 261 32];
app.DesignareflectarrayLabel.Text = ‘Design a reflectarray ‘;
% Create AntennaradiusEditFieldLabel
app.AntennaradiusEditFieldLabel = uilabel(app.UIFigure);
app.AntennaradiusEditFieldLabel.HorizontalAlignment = ‘center’;
app.AntennaradiusEditFieldLabel.Position = [22 553 53 30];
app.AntennaradiusEditFieldLabel.Text = {‘Antenna ‘; ‘radius’};
% Create Antennaradius
app.Antennaradius = uieditfield(app.UIFigure, ‘numeric’);
app.Antennaradius.ValueChangedFcn = createCallbackFcn(app, @AntennaradiusEditFieldValueChanged, true);
app.Antennaradius.Position = [90 561 100 22];
% Create FrequencyEditFieldLabel
app.FrequencyEditFieldLabel = uilabel(app.UIFigure);
app.FrequencyEditFieldLabel.HorizontalAlignment = ‘right’;
app.FrequencyEditFieldLabel.Position = [10 522 65 22];
app.FrequencyEditFieldLabel.Text = ‘Frequency ‘;
% Create Frequency
app.Frequency = uieditfield(app.UIFigure, ‘numeric’);
app.Frequency.RoundFractionalValues = ‘on’;
app.Frequency.ValueChangedFcn = createCallbackFcn(app, @AntennaradiusEditFieldValueChanged, true);
app.Frequency.Position = [90 522 100 22];
% Create Image
app.Image = uiimage(app.UIFigure);
app.Image.Position = [231 345 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.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.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.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.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.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 DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel = uilabel(app.UIFigure);
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.BackgroundColor = [0.651 0.651 0.651];
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.FontSize = 14;
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.Position = [661 39 260 76];
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.Text = {‘Desigener Eng .Abdullah Sabah Ibrahim’; ‘Air Navigation Engineer’; ‘uabd704@gmail.com’};
% Create ElementDataLabel
app.ElementDataLabel = uilabel(app.UIFigure);
app.ElementDataLabel.BackgroundColor = [0.502 0.502 0.502];
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 DimensionPrpertyLabel
app.DimensionPrpertyLabel = uilabel(app.UIFigure);
app.DimensionPrpertyLabel.Position = [461 276 104 22];
app.DimensionPrpertyLabel.Text = ‘Dimension/Prperty’;
% Create EditField2
app.EditField2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2.ValueChangedFcn = createCallbackFcn(app, @EditField2ValueChanged, true);
app.EditField2.Position = [461 242 100 22];
app.EditField2.Value = 0.2;
% Create EditField3
app.EditField3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3.Position = [321 243 100 22];
app.EditField3.Value = 140;
% Create EditField3_2
app.EditField3_2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_2.Position = [320.997694832939 203.000512259345 100 22];
app.EditField3_2.Value = 130;
% Create EditField3_3
app.EditField3_3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_3.Position = [320.995929173063 161.393369402201 100 22];
% Create EditField2_2
app.EditField2_2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_2.Position = [461 203 100 22];
app.EditField2_2.Value = 1.5;
% Create EditField2_3
app.EditField2_3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_3.Position = [461 163 100 22];
app.EditField2_3.Value = 2.5;
% Create EditField3_4
app.EditField3_4 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_4.Position = [321 123 100 22];
app.EditField3_4.Value = -150;
% Create EditField2_4
app.EditField2_4 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_4.Position = [460.107943943571 122.820894513809 100 22];
app.EditField2_4.Value = 3.5;
% Create EditField2_5
app.EditField2_5 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_5.Position = [461 83 100 22];
app.EditField2_5.Value = 4.5;
% Create EditField3_5
app.EditField3_5 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_5.Position = [320.997989109585 81.5705348423533 100 22];
app.EditField3_5.Value = -175;
% 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
endclassdef 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
EditField3_5 matlab.ui.control.NumericEditField
EditField2_5 matlab.ui.control.NumericEditField
EditField2_4 matlab.ui.control.NumericEditField
EditField3_4 matlab.ui.control.NumericEditField
EditField2_3 matlab.ui.control.NumericEditField
EditField2_2 matlab.ui.control.NumericEditField
EditField3_3 matlab.ui.control.NumericEditField
EditField3_2 matlab.ui.control.NumericEditField
EditField3 matlab.ui.control.NumericEditField
EditField2 matlab.ui.control.NumericEditField
DimensionPrpertyLabel matlab.ui.control.Label
PhaseLabel matlab.ui.control.Label
ElementDataLabel matlab.ui.control.Label
DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel 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
FrequencyEditFieldLabel matlab.ui.control.Label
Antennaradius matlab.ui.control.NumericEditField
AntennaradiusEditFieldLabel 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)
% — Executes on button press in pushbutton2.
% Create GUIDE-style callback args – Added by Migration Tool
[hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
% 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)
handles = guidata(hObject);
addpath(genpath(‘C:UsersseymurDesktopcst-matlabCST-MATLAB-API-master’));
cst = actxserver(‘CSTStudio.application’);
mws = cst.invoke(‘NewMWS’);
cst = actxserver(‘CSTStudio.Application’);
mws = cst.OpenFile(‘path_to_your_cst_file.cst’);
fmin=2.2;
fmax=2.6;
function CstDefineFrequencyRange(mws, startFreq, endFreq)
mws.invoke(‘FrequencyRange’, ‘Define’, startFreq, endFreq);
end
mws = cst.invoke(‘NewMWS’);
Xmin=’expanded open’;
Xmax=’expanded open’;
Ymin=’expanded open’;
Ymax=’expanded open’;
Zmin=’expanded open’;
Zmax=’expanded open’;
minfrequency = fmin;
function CstDefineOpenBoundary(mws, minfrequency, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax)
% CstDefineOpenBoundary – Defines the open boundary in CST.
%
% Inputs:
% mws – CST Microwave Studio object
% minfrequency – Minimum frequency for the boundary
% Xmin, Xmax, Ymin, Ymax, Zmin, Zmax – Boundary limits in each direction
% Assuming CST’s boundary settings are being configured using invoke calls
invoke(mws, ‘Boundary’, ‘Define’, ‘Xmin’, Xmin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Xmax’, Xmax);
invoke(mws, ‘Boundary’, ‘Define’, ‘Ymin’, Ymin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Ymax’, Ymax);
invoke(mws, ‘Boundary’, ‘Define’, ‘Zmin’, Zmin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Zmax’, Zmax);
% Set minimum frequency (this part may vary depending on how CST handles this)
invoke(mws, ‘Solver’, ‘FrequencyRange’, minfrequency);
end
freq = app.Frequency.Value * 10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
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;
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;
% phas_lin_map=m_phase_deg*m+n;
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
m_phase=mod(phase,2*pi);
m_phase_deg=m_phase*180/pi;
m_phase_deg(:);
surf(app.UIAxes, m_phase_deg);
view(app.UIAxes, 2);
surf(m_phase_deg)
view(2)
guidata(hObject, handles);
end
% Value changed function: Antennaradius, Frequency
function AntennaradiusEditFieldValueChanged(app, event)
value = app.Antennaradius.Value;
end
% Button pushed function: PreviewButton
function PreviewButtonPushed(app, event)
% 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 = [140 0.2; 130 1.5; 0 2.5; -150 3.5; -175 4.5];
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
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
delete(app)
end
% Value changed function: EditField2
function EditField2ValueChanged(app, event)
value = app.EditField2.Value;
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);
app.UIAxes.XColor = [0 0 0];
app.UIAxes.Position = [602 321 329 262];
% Create DesignareflectarrayLabel
app.DesignareflectarrayLabel = uilabel(app.UIFigure);
app.DesignareflectarrayLabel.FontSize = 24;
app.DesignareflectarrayLabel.FontWeight = ‘bold’;
app.DesignareflectarrayLabel.Position = [363 593 261 32];
app.DesignareflectarrayLabel.Text = ‘Design a reflectarray ‘;
% Create AntennaradiusEditFieldLabel
app.AntennaradiusEditFieldLabel = uilabel(app.UIFigure);
app.AntennaradiusEditFieldLabel.HorizontalAlignment = ‘center’;
app.AntennaradiusEditFieldLabel.Position = [22 553 53 30];
app.AntennaradiusEditFieldLabel.Text = {‘Antenna ‘; ‘radius’};
% Create Antennaradius
app.Antennaradius = uieditfield(app.UIFigure, ‘numeric’);
app.Antennaradius.ValueChangedFcn = createCallbackFcn(app, @AntennaradiusEditFieldValueChanged, true);
app.Antennaradius.Position = [90 561 100 22];
% Create FrequencyEditFieldLabel
app.FrequencyEditFieldLabel = uilabel(app.UIFigure);
app.FrequencyEditFieldLabel.HorizontalAlignment = ‘right’;
app.FrequencyEditFieldLabel.Position = [10 522 65 22];
app.FrequencyEditFieldLabel.Text = ‘Frequency ‘;
% Create Frequency
app.Frequency = uieditfield(app.UIFigure, ‘numeric’);
app.Frequency.RoundFractionalValues = ‘on’;
app.Frequency.ValueChangedFcn = createCallbackFcn(app, @AntennaradiusEditFieldValueChanged, true);
app.Frequency.Position = [90 522 100 22];
% Create Image
app.Image = uiimage(app.UIFigure);
app.Image.Position = [231 345 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.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.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.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.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.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 DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel = uilabel(app.UIFigure);
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.BackgroundColor = [0.651 0.651 0.651];
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.FontSize = 14;
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.Position = [661 39 260 76];
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.Text = {‘Desigener Eng .Abdullah Sabah Ibrahim’; ‘Air Navigation Engineer’; ‘uabd704@gmail.com’};
% Create ElementDataLabel
app.ElementDataLabel = uilabel(app.UIFigure);
app.ElementDataLabel.BackgroundColor = [0.502 0.502 0.502];
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 DimensionPrpertyLabel
app.DimensionPrpertyLabel = uilabel(app.UIFigure);
app.DimensionPrpertyLabel.Position = [461 276 104 22];
app.DimensionPrpertyLabel.Text = ‘Dimension/Prperty’;
% Create EditField2
app.EditField2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2.ValueChangedFcn = createCallbackFcn(app, @EditField2ValueChanged, true);
app.EditField2.Position = [461 242 100 22];
app.EditField2.Value = 0.2;
% Create EditField3
app.EditField3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3.Position = [321 243 100 22];
app.EditField3.Value = 140;
% Create EditField3_2
app.EditField3_2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_2.Position = [320.997694832939 203.000512259345 100 22];
app.EditField3_2.Value = 130;
% Create EditField3_3
app.EditField3_3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_3.Position = [320.995929173063 161.393369402201 100 22];
% Create EditField2_2
app.EditField2_2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_2.Position = [461 203 100 22];
app.EditField2_2.Value = 1.5;
% Create EditField2_3
app.EditField2_3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_3.Position = [461 163 100 22];
app.EditField2_3.Value = 2.5;
% Create EditField3_4
app.EditField3_4 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_4.Position = [321 123 100 22];
app.EditField3_4.Value = -150;
% Create EditField2_4
app.EditField2_4 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_4.Position = [460.107943943571 122.820894513809 100 22];
app.EditField2_4.Value = 3.5;
% Create EditField2_5
app.EditField2_5 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_5.Position = [461 83 100 22];
app.EditField2_5.Value = 4.5;
% Create EditField3_5
app.EditField3_5 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_5.Position = [320.997989109585 81.5705348423533 100 22];
app.EditField3_5.Value = -175;
% 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 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
EditField3_5 matlab.ui.control.NumericEditField
EditField2_5 matlab.ui.control.NumericEditField
EditField2_4 matlab.ui.control.NumericEditField
EditField3_4 matlab.ui.control.NumericEditField
EditField2_3 matlab.ui.control.NumericEditField
EditField2_2 matlab.ui.control.NumericEditField
EditField3_3 matlab.ui.control.NumericEditField
EditField3_2 matlab.ui.control.NumericEditField
EditField3 matlab.ui.control.NumericEditField
EditField2 matlab.ui.control.NumericEditField
DimensionPrpertyLabel matlab.ui.control.Label
PhaseLabel matlab.ui.control.Label
ElementDataLabel matlab.ui.control.Label
DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel 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
FrequencyEditFieldLabel matlab.ui.control.Label
Antennaradius matlab.ui.control.NumericEditField
AntennaradiusEditFieldLabel 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)
% — Executes on button press in pushbutton2.
% Create GUIDE-style callback args – Added by Migration Tool
[hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
% 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)
handles = guidata(hObject);
addpath(genpath(‘C:UsersseymurDesktopcst-matlabCST-MATLAB-API-master’));
cst = actxserver(‘CSTStudio.application’);
mws = cst.invoke(‘NewMWS’);
cst = actxserver(‘CSTStudio.Application’);
mws = cst.OpenFile(‘path_to_your_cst_file.cst’);
fmin=2.2;
fmax=2.6;
function CstDefineFrequencyRange(mws, startFreq, endFreq)
mws.invoke(‘FrequencyRange’, ‘Define’, startFreq, endFreq);
end
mws = cst.invoke(‘NewMWS’);
Xmin=’expanded open’;
Xmax=’expanded open’;
Ymin=’expanded open’;
Ymax=’expanded open’;
Zmin=’expanded open’;
Zmax=’expanded open’;
minfrequency = fmin;
function CstDefineOpenBoundary(mws, minfrequency, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax)
% CstDefineOpenBoundary – Defines the open boundary in CST.
%
% Inputs:
% mws – CST Microwave Studio object
% minfrequency – Minimum frequency for the boundary
% Xmin, Xmax, Ymin, Ymax, Zmin, Zmax – Boundary limits in each direction
% Assuming CST’s boundary settings are being configured using invoke calls
invoke(mws, ‘Boundary’, ‘Define’, ‘Xmin’, Xmin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Xmax’, Xmax);
invoke(mws, ‘Boundary’, ‘Define’, ‘Ymin’, Ymin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Ymax’, Ymax);
invoke(mws, ‘Boundary’, ‘Define’, ‘Zmin’, Zmin);
invoke(mws, ‘Boundary’, ‘Define’, ‘Zmax’, Zmax);
% Set minimum frequency (this part may vary depending on how CST handles this)
invoke(mws, ‘Solver’, ‘FrequencyRange’, minfrequency);
end
freq = app.Frequency.Value * 10^9;
lambda = physconst(‘LightSpeed’)*1000/freq;
k=2*pi/lambda;
ix=1;
iy=1;
data=handles.data;
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;
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;
% phas_lin_map=m_phase_deg*m+n;
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
m_phase=mod(phase,2*pi);
m_phase_deg=m_phase*180/pi;
m_phase_deg(:);
surf(app.UIAxes, m_phase_deg);
view(app.UIAxes, 2);
surf(m_phase_deg)
view(2)
guidata(hObject, handles);
end
% Value changed function: Antennaradius, Frequency
function AntennaradiusEditFieldValueChanged(app, event)
value = app.Antennaradius.Value;
end
% Button pushed function: PreviewButton
function PreviewButtonPushed(app, event)
% 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 = [140 0.2; 130 1.5; 0 2.5; -150 3.5; -175 4.5];
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
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
delete(app)
end
% Value changed function: EditField2
function EditField2ValueChanged(app, event)
value = app.EditField2.Value;
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);
app.UIAxes.XColor = [0 0 0];
app.UIAxes.Position = [602 321 329 262];
% Create DesignareflectarrayLabel
app.DesignareflectarrayLabel = uilabel(app.UIFigure);
app.DesignareflectarrayLabel.FontSize = 24;
app.DesignareflectarrayLabel.FontWeight = ‘bold’;
app.DesignareflectarrayLabel.Position = [363 593 261 32];
app.DesignareflectarrayLabel.Text = ‘Design a reflectarray ‘;
% Create AntennaradiusEditFieldLabel
app.AntennaradiusEditFieldLabel = uilabel(app.UIFigure);
app.AntennaradiusEditFieldLabel.HorizontalAlignment = ‘center’;
app.AntennaradiusEditFieldLabel.Position = [22 553 53 30];
app.AntennaradiusEditFieldLabel.Text = {‘Antenna ‘; ‘radius’};
% Create Antennaradius
app.Antennaradius = uieditfield(app.UIFigure, ‘numeric’);
app.Antennaradius.ValueChangedFcn = createCallbackFcn(app, @AntennaradiusEditFieldValueChanged, true);
app.Antennaradius.Position = [90 561 100 22];
% Create FrequencyEditFieldLabel
app.FrequencyEditFieldLabel = uilabel(app.UIFigure);
app.FrequencyEditFieldLabel.HorizontalAlignment = ‘right’;
app.FrequencyEditFieldLabel.Position = [10 522 65 22];
app.FrequencyEditFieldLabel.Text = ‘Frequency ‘;
% Create Frequency
app.Frequency = uieditfield(app.UIFigure, ‘numeric’);
app.Frequency.RoundFractionalValues = ‘on’;
app.Frequency.ValueChangedFcn = createCallbackFcn(app, @AntennaradiusEditFieldValueChanged, true);
app.Frequency.Position = [90 522 100 22];
% Create Image
app.Image = uiimage(app.UIFigure);
app.Image.Position = [231 345 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.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.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.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.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.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 DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel = uilabel(app.UIFigure);
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.BackgroundColor = [0.651 0.651 0.651];
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.FontSize = 14;
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.Position = [661 39 260 76];
app.DesigenerEngAbdullahSabahIbrahimuabd704gmailcomLabel.Text = {‘Desigener Eng .Abdullah Sabah Ibrahim’; ‘Air Navigation Engineer’; ‘uabd704@gmail.com’};
% Create ElementDataLabel
app.ElementDataLabel = uilabel(app.UIFigure);
app.ElementDataLabel.BackgroundColor = [0.502 0.502 0.502];
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 DimensionPrpertyLabel
app.DimensionPrpertyLabel = uilabel(app.UIFigure);
app.DimensionPrpertyLabel.Position = [461 276 104 22];
app.DimensionPrpertyLabel.Text = ‘Dimension/Prperty’;
% Create EditField2
app.EditField2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2.ValueChangedFcn = createCallbackFcn(app, @EditField2ValueChanged, true);
app.EditField2.Position = [461 242 100 22];
app.EditField2.Value = 0.2;
% Create EditField3
app.EditField3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3.Position = [321 243 100 22];
app.EditField3.Value = 140;
% Create EditField3_2
app.EditField3_2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_2.Position = [320.997694832939 203.000512259345 100 22];
app.EditField3_2.Value = 130;
% Create EditField3_3
app.EditField3_3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_3.Position = [320.995929173063 161.393369402201 100 22];
% Create EditField2_2
app.EditField2_2 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_2.Position = [461 203 100 22];
app.EditField2_2.Value = 1.5;
% Create EditField2_3
app.EditField2_3 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_3.Position = [461 163 100 22];
app.EditField2_3.Value = 2.5;
% Create EditField3_4
app.EditField3_4 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_4.Position = [321 123 100 22];
app.EditField3_4.Value = -150;
% Create EditField2_4
app.EditField2_4 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_4.Position = [460.107943943571 122.820894513809 100 22];
app.EditField2_4.Value = 3.5;
% Create EditField2_5
app.EditField2_5 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField2_5.Position = [461 83 100 22];
app.EditField2_5.Value = 4.5;
% Create EditField3_5
app.EditField3_5 = uieditfield(app.UIFigure, ‘numeric’);
app.EditField3_5.Position = [320.997989109585 81.5705348423533 100 22];
app.EditField3_5.Value = -175;
% 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 app designer MATLAB Answers — New Questions