Programmatically placing plots into a subplot

4 views (last 30 days)
Jrod H
Jrod H on 18 Feb 2022
Answered: VINAYAK LUHA on 11 Oct 2023
I am programatically working with the antenna toolbox and getting a bunch of plots for impedance, S11, pattern, etc. I have tried to put these into a subplot, but it seems this will not work for me. The plots are interally created by calling built-in fucntions such as impedance( ), sparameters( ), current( ), pattern( ), patternAzimuth( ), and patternElevation( ). Unfortunately I do not see a way to get a figure handle from these built in functions. Is there a work around so I can have a single subplot with all of these figures in one window?
Thanks,
Jrod
  2 Comments
Star Strider
Star Strider on 18 Feb 2022
I don’t have the Antenna Toolbox, however I can likely access it here with the online Run feature.
Please post relevant parts of your code (including necessary data, preferably as text or spreadsheet files since dealing with .mat files with the online Run feature can be challenging) so that it is possible to run it and experiment with it. (Some Toolbox plots, such as those produced by the Control System Toolbox, can be challenging to modify, however getting relevant properties and using them is usually possible.)
Jrod H
Jrod H on 18 Feb 2022
Edited: Jrod H on 18 Feb 2022
Thank you Star Strider! The code below should work in Matlab 2020b. You should see seven different figures pop up. I would like to find a way to arrange all of the figures into a single window if possible. I tried using subplot and also GCF, but neither was letting me do what I had hoped for.
clc; clear; close all;
%% Constants
c = physconst('lightspeed');
frequency = 2.45e9;
Z0 = 50;
numFreqPoints = 5;
%% Initial Calculations
lambda_m = c / frequency;
BW = 100e6;
fmin = frequency - BW;
fmax = frequency + BW;
freqRange = linspace(fmin, fmax, numFreqPoints);
%% Create The initial Default Antenna Object And Plot It
insetPatch = design(patchMicrostripInsetfed, frequency);
antennaPlotting(insetPatch, freqRange, frequency)
%% Create The Plots
function plots = antennaPlotting(antObj, freqRange, freq)
%Show antenna model
figure('Name', 'Antenna Geometry', 'NumberTitle', 'off')
show(antObj);
%impedance for dipole
figure('Name', 'Impedance', 'NumberTitle', 'off');
impedance(antObj, freqRange);
%s11 for dipole
figure('Name', 'S11', 'NumberTitle', 'off');
s = sparameters(antObj, freqRange);
rfplot(s)
%current for dipole
figure('Name', 'Current Distribution', 'NumberTitle', 'off');
current(antObj, freq);
%pattern for dipole
figure('Name', '3D Pattern', 'NumberTitle', 'off');
pattern(antObj, freq);
%azimuth for dipole
figure('Name', 'Azimuthal Pattern', 'NumberTitle', 'off');
patternAzimuth(antObj, freq, 0, 'Azimuth', [0:5:360]);
%elevation for dipole
figure('Name', 'Elevation Pattern', 'NumberTitle', 'off');
patternElevation(antObj, freq, 0, 'Elevation', [0:5:360]);
end

Sign in to comment.

Answers (1)

VINAYAK LUHA
VINAYAK LUHA on 11 Oct 2023
Hi Jrod,
I understand that you are utilizing built-in functions from the Antenna Toolbox to generate various plots. However, you are seeking a solution to organize these plots into subplots within a single figure.
Here is a workaround which involves saving the generated figures and then arranging them in subplots:
  1. Firstly, Save each of the generated figures as ".fig" files using the "savefig" function. Refer to the documentation of "savefig" here - https://in.mathworks.com/help/matlab/ref/savefig.html .
  2. Next, For arranging MATLAB figure (.fig) files into subplots, you can refer to the following MATLAB answers post: https://in.mathworks.com/matlabcentral/answers/101806-how-can-i-insert-my-matlab-figure-fig-files-into-multiple-subplots .
I hope this helps you organize your plots into subplots within a single figure.
Regards,
Vinayak Luha

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!