Effacer les filtres
Effacer les filtres

App designer - I can't resolve two bugs in my programme

3 vues (au cours des 30 derniers jours)
Andy
Andy le 16 Fév 2024
Commenté : Voss le 16 Fév 2024
Hi,
I was wondering if anyone can have a quick look over my Appdesigner code as there are two bugs I just can't seem to resolve.
The programme is for simulating EM Waves and the Design View looks as shown below:
The problem I am having is in two parts, within the Code View.
Problem 1 is a SWITCH statement which is not chosing CASE 5, and allowing a plot to open where I can input user defined information onto a figure by clicking my mouse button. The other four statements excute fine!
Problem 2 is the plotting on UIAxes 2 using imagesc with elements plotted on top. When I try to plot the hold on doesn't seem to work and the image disappears leaving the contents of the last plot.
I have included the full code in just case the problem may be further up in the programme.
The two problems are highlighted with the code as =============== PROBLEM X ========================= to make it easy to find.
I hope someone may be able to resolve these two problems, as it is driving me mad.
Thanks,
Andy
classdef Time_Reversal_App_Stage3 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ArraySetupButton matlab.ui.control.Button
TransmitButton matlab.ui.control.Button
TimeReverseButton matlab.ui.control.Button
SendSignalButton matlab.ui.control.Button
TypeofSignalButtonGroup matlab.ui.container.ButtonGroup
GaussianPulseButton matlab.ui.control.RadioButton
SinewaveButton matlab.ui.control.RadioButton
SelectMediaButtonGroup matlab.ui.container.ButtonGroup
UserDefinedButton matlab.ui.control.RadioButton
WaveguideButton matlab.ui.control.RadioButton
NoLineofSightButton matlab.ui.control.RadioButton
LineofSightButton matlab.ui.control.RadioButton
FreeSpaceButton matlab.ui.control.RadioButton
Offset10EditField matlab.ui.control.NumericEditField
Offset10EditFieldLabel matlab.ui.control.Label
Distance180EditField matlab.ui.control.NumericEditField
Distance180EditFieldLabel matlab.ui.control.Label
DistancebetweenTxRxLabel matlab.ui.control.Label
Spacing1EditField matlab.ui.control.NumericEditField
Spacing1EditFieldLabel matlab.ui.control.Label
NoofElements4EditField matlab.ui.control.NumericEditField
NoofElements4EditFieldLabel matlab.ui.control.Label
ArrayStart10EditField matlab.ui.control.NumericEditField
ArrayStart10EditFieldLabel matlab.ui.control.Label
ReceiveAntennaParametersLabel matlab.ui.control.Label
Receiver50EditField matlab.ui.control.NumericEditField
Receiver50EditFieldLabel matlab.ui.control.Label
Y200EditField matlab.ui.control.NumericEditField
Y200EditFieldLabel matlab.ui.control.Label
FundamentalParametersLabel matlab.ui.control.Label
X100EditField matlab.ui.control.NumericEditField
X100EditFieldLabel matlab.ui.control.Label
UIAxes3 matlab.ui.control.UIAxes
UIAxes2 matlab.ui.control.UIAxes
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
% Inputs:
% imax: size of grid in x-direction (in number of cells)
% jmax: size of grid in y-direction (in number of cells)
% del: size of cell in meters( needs to be less than lambda/10)
% signal: matrix with row vectors of signal (Input Signal)
% space: the number of cells between transmitters
% start: the cell at which the first trasnmitter is located
% array: the number of elements in the receiving array
% rstart: the x-coordinate of the first receiver
% rspace: the spacing between receivers
% depth: the distance between the receiving array and the transmitting array
% offset: the distance from zero in the x-direction where the simulation will start
% media: value between 1 and 5 that deterines the type of environment in which the expermient takes
%place
% ER: when media=5, a user defined environment is provided
%
% Outputs:
% E: Outputs the final electric field
% V: Outputs the received signal at certain points (array elements for forward migration, receiver for
% reverse migration)
% frames: a slide show that shows the evolution of E over time. Can be converted into AVI format using
% movie2avi command
% Description
X
Y
receiver
arraystart
elements
arrayspace
rarrayspace
depth
offset
media
signal
er
c
fc
lambda
del
dt
Fs
t
ax
delay
d_hat
stop
temp
E1
V1
E2
send
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: X100EditField
function X100EditFieldValueChanged(app, event)
app.X = app.X100EditField.Value;
end
% Value changed function: Y200EditField
function Y200EditFieldValueChanged(app, event)
app.Y = app.Y200EditField.Value;
end
% Value changed function: Receiver50EditField
function Receiver50EditFieldValueChanged(app, event)
app.receiver = app.Receiver50EditField.Value;
end
% Value changed function: ArrayStart10EditField
function ArrayStart10EditFieldValueChanged(app, event)
app.arraystart = app.ArrayStart10EditField.Value;
end
% Value changed function: NoofElements4EditField
function NoofElements4EditFieldValueChanged(app, event)
app.elements = app.NoofElements4EditField.Value;
end
% Value changed function: Spacing1EditField
function Spacing1EditFieldValueChanged(app, event)
app.arrayspace = app.Spacing1EditField.Value;
end
% Value changed function: Distance180EditField
function Distance180EditFieldValueChanged(app, event)
app.depth = app.Distance180EditField.Value;
end
% Value changed function: Offset10EditField
function Offset10EditFieldValueChanged(app, event)
app.offset = app.Offset10EditField.Value;
end
% Selection changed function: SelectMediaButtonGroup
function SelectMediaButtonGroupSelectionChanged(app, event)
if app.FreeSpaceButton.Value == 1
app.media = 1;
elseif app.LineofSightButton.Value == 1
app.media = 2;
elseif app.NoLineofSightButton.Value == 1
app.media = 3;
elseif app.WaveguideButton.Value == 1
app.media = 4;
elseif app.UserDefinedButton == 1
app.media = 5;
if app.media == 5
app.er;
else
app.er = 0;
end
end
end
% Selection changed function: TypeofSignalButtonGroup
function TypeofSignalButtonGroupSelectionChanged(app, event)
app.c = 3E8;
app.fc = 2.45e9;
app.lambda = app.c/app.fc;
% Length in metres of each cell
app.del = app.lambda/10; %convert into metres
app.dt = (1/(app.c*sqrt((1/app.del)^2+(1/app.del)^2)));
app.Fs = 1/app.dt;
app.t = 0:1/app.Fs:300/app.Fs-1/app.Fs;
% Select the signal
if app.SinewaveButton.Value == 1
app.signal = sin(2*pi*app.fc*app.t);
elseif app.GaussianPulseButton.Value == 1
app.signal = gauspuls(app.t,app.fc,0.5);
end
end
% Button pushed function: SendSignalButton
function SendSignalButtonPushed(app, event)
% Read value from X & Y
app.X = app.X100EditField.Value;
app.Y = app.Y200EditField.Value;
% Plot chosen signal onto signal transmitted plot
plot(app.UIAxes3,app.signal)
title(app.UIAxes3,'Signal sent from transmitter')
% Define axis to plot
axis(app.UIAxes,'image');
app.ax = app.UIAxes;
% Call function FDTD
[app.E1] = fdtd_time_reversal(app.X, app.Y, app.del, app.signal, app.receiver, app.elements, 1, app.arrayspace, 1, app.depth, app.offset, app.media, app.er, app.ax);
imagesc(app.UIAxes,app.E1)
axis(app.UIAxes, 'image')
xlim(app.UIAxes, 'tight')
ylim(app.UIAxes, 'tight')
drawnow
[app.V1] = fdtd_time_reversal(app.X, app.Y, app.del, app.signal, app.receiver, app.elements, 1, app.arrayspace, 1, app.depth, app.offset, app.media, app.er, app.ax);
plot(app.UIAxes3,1:length(app.V1),app.V1)
title(app.UIAxes3,'Recorded signal at array elements')
end
% Button pushed function: TimeReverseButton
function TimeReverseButtonPushed(app, event)
% Time reversal
app.elements = app.NoofElements4EditField.Value;
for k = 1:app.elements
app.delay(k) = find(abs(app.V1(k,:))>1E-6, 1);
end
% d_hat represents the delay from the start of the simulation
% to the time when the first element records a signal
app.d_hat = min(app.delay);
% Determine the delay for each signal relative to the first signal
app.delay = app.delay - app.d_hat;
app.stop = app.d_hat + app.depth;
if app.stop >= length(app.V1)
app.stop = length(app.V1);
end
% Create the signal to send to the receiver
for k = 1:app.elements
app.temp(k,:) = [zeros(1,round(2*app.depth)) app.V1(k,app.d_hat:app.stop)];
end
% Flip the signal and normalize to 1
app.send = fliplr(app.temp/max(max(abs(abs(app.temp)))));
plot(app.UIAxes3, 1:length(app.send),app.send)
title(app.UIAxes3,'Time Reversed Signal')
end
% Button pushed function: TransmitButton
function TransmitButtonPushed(app, event)
if app.media == 5
app.er;
else
app.er = 0;
end
% Define axis to plot
axis(app.UIAxes,'image');
app.ax = app.UIAxes;
% Call function FDTD
[app.E2] = fdtd_time_reversal(app.X, app.Y, app.del, app.send, app.arraystart, app.elements, app.receiver , 1, 1, -app.depth, app.offset + app.depth, app.media, app.er, app.ax);
imagesc(app.UIAxes,app.E2)
axis(app.UIAxes, 'image')
xlim(app.UIAxes, 'tight')
ylim(app.UIAxes, 'tight')
drawnow
end
% Button pushed function: ArraySetupButton
function ArraySetupButtonPushed(app, event)
% Determine where the array is?
center = app.arraystart + ((app.elements-1)/2)*app.arrayspace;
edge1 = app.arraystart;
edge2 = app.arraystart + (app.elements-1)*app.arrayspace;
length = (app.offset + app.depth);
left = app.offset;
right = app.offset + app.depth;
%Define the realtive permativitty of each point in the simulation
app.er=ones(app.X,app.Y);
pointsy1=round((app.Y-3)*[ 0.7271 0.3093 0.8385 0.5681 0.3704 0.7027 0.5466 0.4449 0.6946 0.6213])+3;
pointsy2=round((app.Y-3)*[ 0.1365 0.0118 0.8939 0.1991 0.2987 0.6614 0.2844 0.4692 0.0648 0.9883])+3;
pointsx1=round((app.X/2-10)*[ 0.7948 0.9568 0.5226 0.8801 0.1730 0.9797 0.2714 0.2523 0.8757 0.7373])+3;
pointsx2=round((app.X/2-10)*[0.5828 0.4235 0.5155 0.3340 0.4329 0.2259 0.5798 0.7604 0.5298 0.6405])+(app.X/2+8);
points=[[pointsx1 pointsx2]' [pointsy1 pointsy2]'];
scatter=20;
%==================================================================================================================================
% PROBLEM 1 HERE
%===================================================================================================================================
%Provide the desired environment
nb = 32;
switch app.media
case 1 % Free Space
case 2 % Line of Sight
for i=1:scatter
app.er(nb+points(i,1)-2:nb+points(i,1)+2,nb+points(i,2)-2:nb+points(i,2)+2)=100*ones(5,5);
end
case 3 % No Line of Sight
app.er(nb+center-4:nb+center+4,nb+left+(right-left)/2-4:nb+left+(right-left)/2+4)=100*ones(9,9);
for i=1:scatter
app.er(nb+points(i,1)-2:nb+points(i,1)+2,nb+points(i,2)-2:nb+points(i,2)+2)=100*ones(5,5);
end
case 4 % Waveguide
app.er(nb+edge1-2,nb+(0:length-1))=100*ones(1,length);
app.er(nb+edge2+2,nb+(0:length-1))=100*ones(1,length);
case 5 %User Defined Input
figure(1)
hold on
plot(app.offset,app.receiver,'marker','<','markerfacecolor','y','markeredgecolor','b','linestyle',':', 'markersize', 5)
hold on
plot(app.offset + app.depth*ones(1,app.elements),app.arraystart:app.arrayspace:app.arraystart+(app.elements-1)*app.arrayspace,'marker','>','markerfacecolor','y','markeredgecolor','b','linestyle',':','markersize', 5);
axis equal
axis([1 app.Y 1 app.X])
title('Place Reflectors with Left Mouse Button, Press Right Mouse Button When Finished')
xlabel('Y')
ylabel('X')
view([0 270])
figure(1)
check=1;
grid on
grid minor
%Allow the user to place their own reflectors
while check == 1
[x,y,button]=ginput(1);
if button==3
check=0;
else
plot(round(x),round(y),'marker','square','markerfacecolor','r','markeredgecolor','k','markersize', 5)
axis([1 app.Y 1 app.X])
app.er(round(y),round(x))=1000;
end
end
hold off
close
end
%Plot the simulation space
% =======================================================================================================================
% PROBLEM 2 HERE
% =======================================================================================================================
axis(app.UIAxes2,[1 app.Y 1 app.X],'image')
colormap(jet)
imagesc(app.UIAxes2,app.er)
xlim(app.UIAxes2, 'tight')
ylim(app.UIAxes2, 'tight')
hold on
plot(app.UIAxes2,app.offset,app.receiver,'marker','<','markerfacecolor','y','markeredgecolor','b','linestyle',':', 'markersize', 5)
hold on
plot(app.UIAxes2,(app.offset+app.depth)*ones(1,app.elements),app.arraystart:app.arrayspace:app.arraystart+(app.elements-1)*app.arrayspace,'marker','>','markerfacecolor','y','markeredgecolor','b','linestyle',':','markersize', 5)
xlabel(app.UIAxes2,'Y')
ylabel(app.UIAxes2,'X')
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 1407 755];
app.UIFigure.Name = 'MATLAB App';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Electromagnetic Wave Simulation')
xlabel(app.UIAxes, 'Time (mS)')
ylabel(app.UIAxes, 'E Field (V/m)')
zlabel(app.UIAxes, 'Z')
app.UIAxes.Position = [292 270 864 460];
% Create UIAxes2
app.UIAxes2 = uiaxes(app.UIFigure);
xlabel(app.UIAxes2, 'X')
ylabel(app.UIAxes2, 'Y')
zlabel(app.UIAxes2, 'Z')
app.UIAxes2.Position = [80 11 507 237];
% Create UIAxes3
app.UIAxes3 = uiaxes(app.UIFigure);
title(app.UIAxes3, 'Title')
xlabel(app.UIAxes3, 'Time (mS)')
ylabel(app.UIAxes3, 'Y')
zlabel(app.UIAxes3, 'Z')
app.UIAxes3.Position = [610 11 759 237];
% Create X100EditFieldLabel
app.X100EditFieldLabel = uilabel(app.UIFigure);
app.X100EditFieldLabel.HorizontalAlignment = 'right';
app.X100EditFieldLabel.Position = [87 690 44 22];
app.X100EditFieldLabel.Text = 'X (100)';
% Create X100EditField
app.X100EditField = uieditfield(app.UIFigure, 'numeric');
app.X100EditField.ValueChangedFcn = createCallbackFcn(app, @X100EditFieldValueChanged, true);
app.X100EditField.Position = [146 690 100 22];
% Create FundamentalParametersLabel
app.FundamentalParametersLabel = uilabel(app.UIFigure);
app.FundamentalParametersLabel.HorizontalAlignment = 'center';
app.FundamentalParametersLabel.FontWeight = 'bold';
app.FundamentalParametersLabel.Position = [95 719 169 22];
app.FundamentalParametersLabel.Text = 'Fundamental Parameters';
% Create Y200EditFieldLabel
app.Y200EditFieldLabel = uilabel(app.UIFigure);
app.Y200EditFieldLabel.HorizontalAlignment = 'right';
app.Y200EditFieldLabel.Position = [87 659 44 22];
app.Y200EditFieldLabel.Text = 'Y (200)';
% Create Y200EditField
app.Y200EditField = uieditfield(app.UIFigure, 'numeric');
app.Y200EditField.ValueChangedFcn = createCallbackFcn(app, @Y200EditFieldValueChanged, true);
app.Y200EditField.Position = [146 659 100 22];
% Create Receiver50EditFieldLabel
app.Receiver50EditFieldLabel = uilabel(app.UIFigure);
app.Receiver50EditFieldLabel.HorizontalAlignment = 'right';
app.Receiver50EditFieldLabel.Position = [55 625 77 22];
app.Receiver50EditFieldLabel.Text = 'Receiver (50)';
% Create Receiver50EditField
app.Receiver50EditField = uieditfield(app.UIFigure, 'numeric');
app.Receiver50EditField.ValueChangedFcn = createCallbackFcn(app, @Receiver50EditFieldValueChanged, true);
app.Receiver50EditField.Position = [147 625 100 22];
% Create ReceiveAntennaParametersLabel
app.ReceiveAntennaParametersLabel = uilabel(app.UIFigure);
app.ReceiveAntennaParametersLabel.HorizontalAlignment = 'center';
app.ReceiveAntennaParametersLabel.FontWeight = 'bold';
app.ReceiveAntennaParametersLabel.Position = [95 591 170 22];
app.ReceiveAntennaParametersLabel.Text = 'Receive Antenna Parameters';
% Create ArrayStart10EditFieldLabel
app.ArrayStart10EditFieldLabel = uilabel(app.UIFigure);
app.ArrayStart10EditFieldLabel.HorizontalAlignment = 'right';
app.ArrayStart10EditFieldLabel.Position = [45 570 87 22];
app.ArrayStart10EditFieldLabel.Text = 'Array Start (10)';
% Create ArrayStart10EditField
app.ArrayStart10EditField = uieditfield(app.UIFigure, 'numeric');
app.ArrayStart10EditField.ValueChangedFcn = createCallbackFcn(app, @ArrayStart10EditFieldValueChanged, true);
app.ArrayStart10EditField.Position = [147 570 100 22];
% Create NoofElements4EditFieldLabel
app.NoofElements4EditFieldLabel = uilabel(app.UIFigure);
app.NoofElements4EditFieldLabel.HorizontalAlignment = 'right';
app.NoofElements4EditFieldLabel.Position = [24 538 112 22];
app.NoofElements4EditFieldLabel.Text = 'No. of Elements (4) ';
% Create NoofElements4EditField
app.NoofElements4EditField = uieditfield(app.UIFigure, 'numeric');
app.NoofElements4EditField.ValueChangedFcn = createCallbackFcn(app, @NoofElements4EditFieldValueChanged, true);
app.NoofElements4EditField.Position = [146 538 100 22];
% Create Spacing1EditFieldLabel
app.Spacing1EditFieldLabel = uilabel(app.UIFigure);
app.Spacing1EditFieldLabel.HorizontalAlignment = 'right';
app.Spacing1EditFieldLabel.Position = [65 504 66 22];
app.Spacing1EditFieldLabel.Text = 'Spacing (1)';
% Create Spacing1EditField
app.Spacing1EditField = uieditfield(app.UIFigure, 'numeric');
app.Spacing1EditField.ValueChangedFcn = createCallbackFcn(app, @Spacing1EditFieldValueChanged, true);
app.Spacing1EditField.Position = [146 504 100 22];
% Create DistancebetweenTxRxLabel
app.DistancebetweenTxRxLabel = uilabel(app.UIFigure);
app.DistancebetweenTxRxLabel.HorizontalAlignment = 'center';
app.DistancebetweenTxRxLabel.FontWeight = 'bold';
app.DistancebetweenTxRxLabel.Position = [103 472 154 22];
app.DistancebetweenTxRxLabel.Text = 'Distance between Tx & Rx';
% Create Distance180EditFieldLabel
app.Distance180EditFieldLabel = uilabel(app.UIFigure);
app.Distance180EditFieldLabel.HorizontalAlignment = 'right';
app.Distance180EditFieldLabel.Position = [48 442 83 22];
app.Distance180EditFieldLabel.Text = 'Distance (180)';
% Create Distance180EditField
app.Distance180EditField = uieditfield(app.UIFigure, 'numeric');
app.Distance180EditField.ValueChangedFcn = createCallbackFcn(app, @Distance180EditFieldValueChanged, true);
app.Distance180EditField.Position = [146 442 100 22];
% Create Offset10EditFieldLabel
app.Offset10EditFieldLabel = uilabel(app.UIFigure);
app.Offset10EditFieldLabel.HorizontalAlignment = 'right';
app.Offset10EditFieldLabel.Position = [71 412 61 22];
app.Offset10EditFieldLabel.Text = 'Offset (10)';
% Create Offset10EditField
app.Offset10EditField = uieditfield(app.UIFigure, 'numeric');
app.Offset10EditField.ValueChangedFcn = createCallbackFcn(app, @Offset10EditFieldValueChanged, true);
app.Offset10EditField.Position = [147 412 100 22];
% Create SelectMediaButtonGroup
app.SelectMediaButtonGroup = uibuttongroup(app.UIFigure);
app.SelectMediaButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @SelectMediaButtonGroupSelectionChanged, true);
app.SelectMediaButtonGroup.TitlePosition = 'centertop';
app.SelectMediaButtonGroup.Title = 'Select Media';
app.SelectMediaButtonGroup.FontWeight = 'bold';
app.SelectMediaButtonGroup.Position = [124 270 123 133];
% Create FreeSpaceButton
app.FreeSpaceButton = uiradiobutton(app.SelectMediaButtonGroup);
app.FreeSpaceButton.Text = 'Free Space';
app.FreeSpaceButton.Position = [11 87 84 22];
app.FreeSpaceButton.Value = true;
% Create LineofSightButton
app.LineofSightButton = uiradiobutton(app.SelectMediaButtonGroup);
app.LineofSightButton.Text = 'Line of Sight';
app.LineofSightButton.Position = [11 65 89 22];
% Create NoLineofSightButton
app.NoLineofSightButton = uiradiobutton(app.SelectMediaButtonGroup);
app.NoLineofSightButton.Text = 'No Line of Sight';
app.NoLineofSightButton.Position = [11 43 107 22];
% Create WaveguideButton
app.WaveguideButton = uiradiobutton(app.SelectMediaButtonGroup);
app.WaveguideButton.Text = 'Waveguide';
app.WaveguideButton.Position = [11 21 82 22];
% Create UserDefinedButton
app.UserDefinedButton = uiradiobutton(app.SelectMediaButtonGroup);
app.UserDefinedButton.Text = 'User Defined';
app.UserDefinedButton.Position = [11 -2 92 22];
% Create TypeofSignalButtonGroup
app.TypeofSignalButtonGroup = uibuttongroup(app.UIFigure);
app.TypeofSignalButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @TypeofSignalButtonGroupSelectionChanged, true);
app.TypeofSignalButtonGroup.TitlePosition = 'centertop';
app.TypeofSignalButtonGroup.Title = 'Type of Signal';
app.TypeofSignalButtonGroup.FontWeight = 'bold';
app.TypeofSignalButtonGroup.Position = [1179 635 190 77];
% Create SinewaveButton
app.SinewaveButton = uiradiobutton(app.TypeofSignalButtonGroup);
app.SinewaveButton.Text = 'Sinewave';
app.SinewaveButton.Position = [11 31 74 22];
app.SinewaveButton.Value = true;
% Create GaussianPulseButton
app.GaussianPulseButton = uiradiobutton(app.TypeofSignalButtonGroup);
app.GaussianPulseButton.Text = 'Gaussian Pulse';
app.GaussianPulseButton.Position = [11 9 106 22];
% Create SendSignalButton
app.SendSignalButton = uibutton(app.UIFigure, 'push');
app.SendSignalButton.ButtonPushedFcn = createCallbackFcn(app, @SendSignalButtonPushed, true);
app.SendSignalButton.FontSize = 18;
app.SendSignalButton.FontWeight = 'bold';
app.SendSignalButton.Position = [1179 538 190 64];
app.SendSignalButton.Text = 'Send Signal';
% Create TimeReverseButton
app.TimeReverseButton = uibutton(app.UIFigure, 'push');
app.TimeReverseButton.ButtonPushedFcn = createCallbackFcn(app, @TimeReverseButtonPushed, true);
app.TimeReverseButton.FontSize = 18;
app.TimeReverseButton.FontWeight = 'bold';
app.TimeReverseButton.Position = [1179 422 190 72];
app.TimeReverseButton.Text = 'Time Reverse';
% Create TransmitButton
app.TransmitButton = uibutton(app.UIFigure, 'push');
app.TransmitButton.ButtonPushedFcn = createCallbackFcn(app, @TransmitButtonPushed, true);
app.TransmitButton.FontSize = 18;
app.TransmitButton.FontWeight = 'bold';
app.TransmitButton.Position = [1179 303 190 76];
app.TransmitButton.Text = 'Transmit';
% Create ArraySetupButton
app.ArraySetupButton = uibutton(app.UIFigure, 'push');
app.ArraySetupButton.ButtonPushedFcn = createCallbackFcn(app, @ArraySetupButtonPushed, true);
app.ArraySetupButton.FontWeight = 'bold';
app.ArraySetupButton.Position = [263 248 135 23];
app.ArraySetupButton.Text = 'Array Setup';
% 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 = Time_Reversal_App_Stage3
% 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
  3 commentaires
Andy
Andy le 16 Fév 2024
Hi VBBV,
The close was there to shut the figure after the user has placed their own refelectors - its a good point I had forgotten that I had originally put that in.
I will remove it and see if it has any affect.
Many thanks,
Andy
Andy
Andy le 16 Fév 2024
Hi VBBV,
No it doesn't seem to have any affect :(
Best regards,
Andy

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 16 Fév 2024
Modifié(e) : Voss le 16 Fév 2024
Problem 1: app.media is never set to 5 because in SelectMediaButtonGroupSelectionChanged, you have:
elseif app.UserDefinedButton == 1
but that should be:
elseif app.UserDefinedButton.Value == 1
Problem 2: Instead of
hold on
you should do
hold(app.UIAxes2,'on')
That is, you should explicitly specify which axes to hold on (same for grid, axis, and anything else where the axes is not explicitly mentioned). Without specifying the axes, hold (and grid, etc.) applies to the current axes, but the current axes may not be app.UIAxes2, particularly if you have multiple axes in your app and other figure(s) open at the same time, etc., etc..
  2 commentaires
Andy
Andy le 16 Fév 2024
Thank you so much Voss, I could have been lucking for those bugs all weekend!
Also I didn't realise about the hold(app.UIAxes2,'on')
Once again, many thanks for your help.
Best regards,
Andy
Voss
Voss le 16 Fév 2024
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by