Clear Filters
Clear Filters

How to program the push button to continue the other push button job in MATLAB GUI

2 views (last 30 days)
Hi
Someone please help me, I created the following code to show the base station and their coverage using push button , but I need to use another push button to add receiver and link/ los between the Tx and Rx.
first push button
function pushbutton1_Callback(hObject, eventdata, handles)
lat=str2num(char(get(handles.lat,'String'))); % get the Latitude from the edit text (lat)
lon=str2num(char(get(handles.lon,'String'))); % get the Longitude from the edit text (lon)
txs = txsite('Latitude',lat, ...
'Longitude',lon, ...
'AntennaHeight',40, ...
'TransmitterFrequency',3500*10^6, ...
'TransmitterPower',20);
viewer1 = siteviewer;
show(txs);
coverage(txs,'close-in','SignalStrengths',-90:10:-20);
second push button
--- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
Rx_lat=str2num(char(get(handles.Rx_lat,'String')));
Rx_lon=str2num(char(get(handles.Rx_long,'String')));
Rx_height=str2num(char(get(handles.Rx_height,'String')));
rxs = rxsite('Latitude',Rx_lat,...
'Longitude',Rx_lon,...
'AntennaHeight',Rx_height);
show(rxs)
los(txs,rxs)
% link(rxs,txs)
I got error when I pressed the second push button

Answers (1)

SACHIN KHANDELWAL
SACHIN KHANDELWAL on 27 May 2024
To implementing the functionality you are describing, you need to make sure that the transmitter sire (tsx) created by the first push button is accessible to the callback function of the second push button, where you create the receiver site(rxs) and display the line-of-sight or link between them.
One possible way to achieve this is by storing "txs" in a place where it can be accessed by both callback functions. In MATLAB GUIs, you can use the "handles" structure to store and retrieve data scross different callback functions.
Here’s how to adjust your code to achieve this:
First push button :
function pushbutton1_Callback(hObject, eventdata, handles)
lat=str2num(char(get(handles.lat,'String'))); % get the Latitude from the edit text (lat)
lon=str2num(char(get(handles.lon,'String'))); % get the Longitude from the edit text (lon)
txs = txsite('Latitude',lat, ...
'Longitude',lon, ...
'AntennaHeight',40, ...
'TransmitterFrequency',3500*10^6, ...
'TransmitterPower',20);
handles.txs = txs; % Store txs in handles for access in other callbacks.
viewer1 = siteviewer;
show(txs);
coverage(txs,'close-in','SignalStrengths',-90:10:-20);
Second push button :
function pushbutton5_Callback(hObject, eventdata, handles)
Rx_lat=str2num(char(get(handles.Rx_lat,'String')));
Rx_lon=str2num(char(get(handles.Rx_long,'String')));
Rx_height=str2num(char(get(handles.Rx_height,'String')));
rxs = rxsite('Latitude',Rx_lat,...
'Longitude',Rx_lon,...
'AntennaHeight',Rx_height);
show(rxs)
los(handles.txs,rxs) % Retrieve txs from handles
% link(rxs,txs)
By storing "txs" in the "handles" structure, you ensure that the transmitter site created by the first push button is easily and reliably accessible to the second push button's callback function for further operations, like creating the receiver site and displaying the line-of-sight or link between them.
I hope you find this information useful.
Thanks!

Categories

Find more on Propagation and Channel Models in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!