Why does the Line Handle Become a Deleted Line Handle in App Designer?

22 views (last 30 days)
I am developing an app that plots performance data in real-time. As part of the app, I have a set of axes to plot 7 lines for different data values whose visibility is controlled by checkbox elements. To control the visibility of the lines, I have callback functions to change the visibility property of each line depending on the checkbox value. However, when I try to control the line properties, I get an error message because the line handle shows as a deleted object. I set public properties for each line handle and when the app opens I have a function that creates a blank plot so the line handle is created and nonempty, and the properties are able to be changed.
function CreateBlankPlot(app)
app.discardsplot = plot(app.UIAxes,datetime('now'),0);
app.retriesplot = plot(app.UIAxes,datetime('now'),0);
app.failsplot = plot(app.UIAxes,datetime('now'),0);
app.recievedplot = plot(app.UIAxes,datetime('now'),0);
app.sentplot = plot(app.UIAxes,datetime('now'),0);
app.RSSIPlot = plot(app.UIAxes,datetime('now'),0);
app.SNRPlot = plot(app.UIAxes,datetime('now'),0);
set(app.discardsplot,'LineStyle','-','Color','green','Marker','o','MarkerFaceColor','green','Visible','off');
set(app.retriesplot,'Visible','off','LineStyle','-','Color','blue','Marker','o','MarkerFaceColor','blue');
set(app.failsplot,'Visible','off','LineStyle','-','Color','red','Marker','o','MarkerFaceColor','red');
set(app.recievedplot,'Visible','off','LineStyle','-','Color','black','Marker','o','MarkerFaceColor','black');
set(app.sentplot,'Visible','off','LineStyle','-','Color','yellow','Marker','o','MarkerFaceColor','yellow');
set(app.RSSIPlot,'Visible','off','LineStyle','-','Color','cyan','Marker','o','MarkerFaceColor','cyan');
set(app.SNRPlot,'Visible','off','LineStyle','-','Color','magenta','Marker','o','MarkerFaceColor','magenta');
end
When I run the code, I get an error message:
Error using matlab.graphics.chart.primitive.Line/set
Invalid or deleted object.
Error in Wifi_Performance_Tool/CreateBlankPlot (line 234)
set(app.discardsplot,'LineStyle','-','Color','green','Marker','o','MarkerFaceColor','green','Visible','off');
Error in Wifi_Performance_Tool/startupFcn (line 255)
CreateBlankPlot(app);
Error in Wifi_Performance_Tool (line 612)
runStartupFcn(app, @startupFcn)
When using breakpoints to diagnose the issue, I see that the line handle shows as a deleted object. However, if I type the same plot command that is in the function into the command window, then the line handle no longer is a deleted object, as shown below.
234 set(app.discardsplot,'LineStyle','-','Color','green','Marker','o','MarkerFaceColor','green','Visible','off');
K>> app.discardsplot
ans =
handle to deleted Line
K>> app.discardsplot = plot(app.UIAxes,datetime('now'),0)
K>> app.discardsplot
ans =
Line with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: 19-Jun-2021 15:42:11
YData: 0
ZData: [1×0 double]
Show all properties
Can someone please explain why the line handle is a deleted object when I run the code in App Designer, but when I run code in the command window, it works as expected?

Accepted Answer

Walter Roberson
Walter Roberson on 19 Jun 2021
you do not have hold turned on so the second plot() removes the first, third removes the second, and so on.
The primative that skips checking holds is to use line() with all name/value pairs

More Answers (0)

Categories

Find more on Develop Apps Using App Designer 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!