Azzera filtri
Azzera filtri

Delete only one smithplot line

4 visualizzazioni (ultimi 30 giorni)
Nils
Nils il 31 Lug 2023
Commentato: Voss il 16 Ago 2023
Hi all,
I'm trying to adapt to the new version of Matlab, so I'm sorry that this is my third question regarding Smith charts.
But this behavior of Matlab / App Designer makes literally no sense to me.
For comparison, I created two programs.
The first program uses the normal plot function to plot two graphs on one Axes, and the second one uses the Smith plot function to plot the S11 parameter of two different dipole antennas on one smith chart.
The first one that works is structured as follows:
It shares the later used h1 and h2 handles with the app.
properties (Access = private)
h1
h2
end
and has two functions: one that runs on startup and one if you press the button.
% Code that executes after component creation
function startupFcn(app)
x = linspace(0,1,50);
app.h1 = plot(app.UIAxes,x,(x).^2);
hold(app.UIAxes,"on");
app.h2 = plot(app.UIAxes,x,(2*x).^2);
end
% Button pushed function: Button
function ButtonPushed(app, event)
delete(app.h2); % this works :)
end
The second Programm that dont work:
properties (Access = private)
s1 % sparameters of normal dipol
s2 % sparameters of dipol with lengh 4
hg1 % handle plot with normal dipol
hg2 % hadnle plot with dipol of lengh 4
end
% Code that executes after component creation
function startupFcn(app)
d1 = dipole;
d2 = dipole("Length",4);
freq = linspace(60e6,90e6,200);
app.s1 = sparameters(d1,freq);
app.s2 = sparameters(d2,freq);
app.hg1 = smithplot(app.s1,'Parent',app.UIAxes);
hold(app.UIAxes,"on");
app.hg2 = smithplot(app.s2,'Parent',app.UIAxes);
end
% Callback function: Button, Slider
function ButtonPushed(app, event)
delete(app.hg2) % This deletes the complete Smith chart :(
end
As written in the comments the second one deletes the whole smith chart all together.
So my question is how can i only remove the second plot (app.hg2) ?
Thanks for your time :)
I attached the two files if you want to compare the behavior of these two programs.

Risposta accettata

Voss
Voss il 31 Lug 2023
Note that the output from smithplot() is a Smith chart object, not a line object as is output from plot, so it makes sense that delete(hg2) deletes the entire Smith chart object. (In fact, app.hg1 and app.hg2 refer to the same Smith chart object, by the way.)
To change what data is displayed on a Smith chart, you can use the add and replace functions.
% some random data:
freq1 = linspace(0,2*pi,50);
data1 = rand(50,1)+1i*rand(50,1);
freq2 = linspace(0,2*pi,10);
data2 = rand(10,1)+1i*rand(10,1);
% make a Smith chart containing both data sets:
ax = axes();
h = smithplot(freq1,data1,'Parent',ax);
hold(ax,"on");
smithplot(freq2,data2,'Parent',ax);
% notice that the Data and Frequency properties of the Smith chart (h)
% contain both data sets:
details(h)
rf.internal.smithplot handle with properties: Interactive: 1 LegendLabels: '' Data: {[50×1 double] [10×1 double]} Frequency: {[50×1 double] [10×1 double]} LegendVisible: 0 TitleTop: '' TitleBottom: '' FontSize: 10 CircleTickLabelColor: 'k' ArcTickLabelColor: 'k' TitleTopFontSizeMultiplier: 1.1000 TitleBottomFontSizeMultiplier: 0.9000 TitleTopFontWeight: 'bold' TitleBottomFontWeight: 'normal' TitleTopTextInterpreter: 'none' TitleBottomTextInterpreter: 'none' TitleTopOffset: 0.1500 TitleBottomOffset: 0.1500 CircleFontSizeMultiplier: 0.9000 ArcFontSizeMultiplier: 1 ArcTickLabelColorMode: 'contrast' ArcTickLabelVisible: 1 CircleTickLabelVisible: 1 GridValue: [2×6 double] ConnectEndpoints: 0 EdgeColor: 'k' LineStyle: '-' LineWidth: 1 GridLineStyle: '-' GridSubLineStyle: '-.' FontName: 'Helvetica' FontSizeMode: 'auto' GridForegroundColor: [0.4000 0.4000 0.4000] GridSubForegroundColor: [0.8000 0.8000 0.8000] GridBackgroundColor: 'w' GridOverData: 0 GridLineWidth: 0.5000 GridSubLineWidth: 0.5000 GridVisible: 1 ClipData: 1 TemporaryCursor: 1 CircleTickLabelColorMode: 'contrast' Marker: 'none' MarkerSize: 6 Parent: [1×1 Figure] NextPlot: 'add' ColorOrder: [7×3 double] ColorOrderIndex: 1 GridType: 'Z' View: 'full'
% just for this demo: copy the axes to another figure, so that the Smith
% plot with both data sets persists when you "delete" the second data set
% in the next step - only for comparison/domstration purposes
copyobj(ax,figure())
% now effectively "delete" the second data set by replacing the data in
% the Smith chart with just the first data set:
replace(h, h.Frequency{1}, h.Data{1})
  3 Commenti
Nils
Nils il 16 Ago 2023
yes it worked, but honestly, I cannot understand why the old smithchart function was removed. But thank you very much for your help :)
Voss
Voss il 16 Ago 2023
You're welcome!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Visualization and Data Export in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by