Delete only one smithplot line
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
Voss
am 31 Jul. 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)
% 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Visualization and Data Export finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!