I want to draw the previous point Delete the next point

%__________________________ This is to return to the previous point
app.i=app.i-1;
if app.i>1
addpoints(app.hnext,app.Cent_Viloc(app.i).Center(1),app.Cent_Viloc(app.i).Center(2))
text(app.UIAxes,app.Cent_Viloc(app.i).Center(1)+0.2,app.Cent_Viloc(app.i).Center(2)+0.2,...
[num2str(app.i),"Volocity : ",num2str(app.Cent_Viloc(app.i).Velocity(1))],"FontSize",10,"FontWeight",...
"bold","Color",'y',...
'BackgroundColor',[1 1 1])
drawnow
end
%__________________________ This is to go to the next point
app.i=app.i+1;
if app.i>1
addpoints(app.hnext,app.Cent_Viloc(app.i).Center(1),app.Cent_Viloc(app.i).Center(2))
text(app.UIAxes,app.Cent_Viloc(app.i).Center(1)+0.2,app.Cent_Viloc(app.i).Center(2)+0.2,...
[num2str(app.i),"Volocity : ",num2str(app.Cent_Viloc(app.i).Velocity(1))],"FontSize",10,...
"FontWeight","bold","Color",'white',...
'BackgroundColor',[0.6 0.2 0.5])
drawnow
end

5 Comments

No idea what the Q? really is, sorry.
Please explain in detail what you're trying to do and where you have a specific problem.
A minimum working example that folks can run that illustrates the issue would be best and more likely to draw attempts than dense code without any inputs to try to use it.
classdef Plot < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
PlotMotionsTab matlab.ui.container.Tab
PlotAllPointsLabel matlab.ui.control.Label
PreviousPointLabel matlab.ui.control.Label
PlotAll matlab.ui.control.Button
PlotPrew matlab.ui.control.Button
NextPointLabel matlab.ui.control.Label
PlotNext matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
Tab2 matlab.ui.container.Tab
end
properties (Access = private)
Cent_Viloc % Description
Direction % Description
i % Description
hnext % Description
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.i=1;
global C
app.Cent_Viloc = C;
app.Cent_Viloc = app.Cent_Viloc(all(~cellfun(@isempty,...
struct2cell(app.Cent_Viloc))));
app.hnext=animatedline("Color",'g','LineStyle','--',...
'LineWidth',1,'Marker','o','MarkerSize',3,'Parent',app.UIAxes);
end
% Button pushed function: PlotNext
function PlotNextPushed(app, event)
app.i=app.i+1;
if app.i>1
addpoints(app.hnext,app.Cent_Viloc(app.i).Center(1),app.Cent_Viloc(app.i).Center(2))
text(app.UIAxes,app.Cent_Viloc(app.i).Center(1)+0.2,app.Cent_Viloc(app.i).Center(2)+0.2,...
[num2str(app.i),"Volocity : ",num2str(app.Cent_Viloc(app.i).Velocity(1))],"FontSize",10,...
"FontWeight","bold","Color",'white',...
'BackgroundColor',[0.6 0.2 0.5])
drawnow
end
end
% Button pushed function: PlotPrew
function PlotPrewButtonPushed(app, event)
%cla(app.UIAxes)
app.i=app.i-1;
if app.i>1
addpoints(app.hnext,app.Cent_Viloc(app.i).Center(1),app.Cent_Viloc(app.i).Center(2))
text(app.UIAxes,app.Cent_Viloc(app.i).Center(1)+0.2,app.Cent_Viloc(app.i).Center(2)+0.2,...
[num2str(app.i),"Volocity : ",num2str(app.Cent_Viloc(app.i).Velocity(1))],"FontSize",10,"FontWeight",...
"bold","Color",'y',...
'BackgroundColor',[1 1 1])
drawnow
end
end
% Button pushed function: PlotAll
function PlotAllButtonPushed(app, event)
global C
h=animatedline(app.UIAxes,"Color",'r',"LineStyle","--","Marker","o","MarkerFaceColor",'g');
C=C(all(~cellfun(@isempty,...
struct2cell(C))));
for j=2:numel(C)
addpoints(h,C(j).Center(1),C(j).Center(2))
text(app.UIAxes,app.Cent_Viloc(app.i).Center(1)+0.2,app.Cent_Viloc(app.i).Center(2)+0.2,...
[num2str(app.i),"Volocity : ",num2str(app.Cent_Viloc(app.i).Velocity(1))],"FontSize",10,"FontWeight",...
"bold","Color",'y',...
'BackgroundColor',[1 1 1])
drawnow
pause(1)
app.Direction(j,1) = C(j).Center(1) - C(j-1).Center(1);
end
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Get the file path for locating images
pathToMLAPP = fileparts(mfilename('fullpath'));
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 672 515];
app.UIFigure.Name = 'MATLAB App';
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [1 1 662 510];
% Create PlotMotionsTab
app.PlotMotionsTab = uitab(app.TabGroup);
app.PlotMotionsTab.Title = 'Plot Motions';
app.PlotMotionsTab.BackgroundColor = [0.3686 0.451 0.5098];
% Create UIAxes
app.UIAxes = uiaxes(app.PlotMotionsTab);
app.UIAxes.XColor = [0.651 0.651 0.651];
app.UIAxes.YColor = [0.651 0.651 0.651];
app.UIAxes.ZColor = 'none';
app.UIAxes.Color = [0 0.4471 0.7412];
app.UIAxes.XGrid = 'on';
app.UIAxes.YGrid = 'on';
app.UIAxes.ZGrid = 'on';
app.UIAxes.ColorOrder = [0 0.447058823529412 0.741176470588235;0.850980392156863 0.325490196078431 0.0980392156862745;0.929411764705882 0.694117647058824 0.125490196078431;0.494117647058824 0.184313725490196 0.556862745098039;0.466666666666667 0.674509803921569 0.188235294117647;0.301960784313725 0.745098039215686 0.933333333333333;0.635294117647059 0.0784313725490196 0.184313725490196];
app.UIAxes.GridColor = [1 1 1];
app.UIAxes.Position = [25 37 579 324];
% Create PlotNext
app.PlotNext = uibutton(app.PlotMotionsTab, 'push');
app.PlotNext.ButtonPushedFcn = createCallbackFcn(app, @PlotNextPushed, true);
app.PlotNext.Icon = fullfile(pathToMLAPP, 'Icons', 'next.png');
app.PlotNext.BackgroundColor = [0.3686 0.451 0.5098];
app.PlotNext.Position = [12 418 100 42];
app.PlotNext.Text = '';
% Create NextPointLabel
app.NextPointLabel = uilabel(app.PlotMotionsTab);
app.NextPointLabel.HorizontalAlignment = 'center';
app.NextPointLabel.FontWeight = 'bold';
app.NextPointLabel.FontColor = [0.8 0.8 0.8];
app.NextPointLabel.Position = [28 459 65 22];
app.NextPointLabel.Text = 'Next Point';
% Create PlotPrew
app.PlotPrew = uibutton(app.PlotMotionsTab, 'push');
app.PlotPrew.ButtonPushedFcn = createCallbackFcn(app, @PlotPrewButtonPushed, true);
app.PlotPrew.Icon = fullfile(pathToMLAPP, 'Icons', 'previous.png');
app.PlotPrew.BackgroundColor = [0.3686 0.451 0.5098];
app.PlotPrew.Position = [141.464285714286 417.107142857143 100 42];
app.PlotPrew.Text = '';
% Create PlotAll
app.PlotAll = uibutton(app.PlotMotionsTab, 'push');
app.PlotAll.ButtonPushedFcn = createCallbackFcn(app, @PlotAllButtonPushed, true);
app.PlotAll.Icon = fullfile(pathToMLAPP, 'Icons', 'play-button (1).png');
app.PlotAll.BackgroundColor = [0.3686 0.451 0.5098];
app.PlotAll.Position = [271.821428571429 417.107142857143 100 42];
app.PlotAll.Text = '';
% Create PreviousPointLabel
app.PreviousPointLabel = uilabel(app.PlotMotionsTab);
app.PreviousPointLabel.HorizontalAlignment = 'center';
app.PreviousPointLabel.FontWeight = 'bold';
app.PreviousPointLabel.FontColor = [0.8 0.8 0.8];
app.PreviousPointLabel.Position = [147 459 90 22];
app.PreviousPointLabel.Text = 'Previous Point';
% Create PlotAllPointsLabel
app.PlotAllPointsLabel = uilabel(app.PlotMotionsTab);
app.PlotAllPointsLabel.HorizontalAlignment = 'center';
app.PlotAllPointsLabel.FontWeight = 'bold';
app.PlotAllPointsLabel.FontColor = [0.8 0.8 0.8];
app.PlotAllPointsLabel.Position = [279 458 86 22];
app.PlotAllPointsLabel.Text = 'Plot All Points';
% Create Tab2
app.Tab2 = uitab(app.TabGroup);
app.Tab2.Title = 'Tab2';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = Plot
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
I want to delete that point from the chart whenever I go to the previous point
AFAIK, TMW did not see fit to provide a method by which to delete an arbitrary point from an animatedline object; that seems an obvious oversight; clearpoints unfortunately doesn't have the option to select a given point from the existing points, but clears the whole line. Doing that and then refreshing with the ones left wanted would undoubtedly cause undesirable repainting the display.
I've not tried it, but the only two choices I see would be
  1. Don't actually remove the point but redraw it in background color so it is not visible -- this may not produce the desired effect because it is still in the line object, so there probably is only one choice left I see...
  2. use the refreshdata method with a data source that you update to remove the point from the X, Y arrays before calling -- I've never tried this with and animated line, so not sure if it works or not; you'll have to 'spearmint and see.
The only other alternative I see OTOMH would be to not use animatedline but revert to plot on a point-by-point basis with the old-school animation technique of simply updating the X|YData arrays directly. Unfortunately, those are not visible with the animated line object.
Thank you very much for your advice
If I could do it in any other way
I will definitely post the method here
dpb
dpb on 20 Aug 2022
Edited: dpb on 20 Aug 2022
Unfortunately, TMW has removed a lot of the previous documentation illustrating these things -- they think animatedline is supposed to be all anybody should ever need -- the only existing example I find in current doc is <trace-marker-along-line>, but it does illustrate the technique of updating the plot handle data directly.
The Q? in your case is what is supposed to happen between points when delete one -- although I guess it's a case of only going back a single step at a time?

Sign in to comment.

 Accepted Answer

dpb
dpb on 20 Aug 2022
Edited: dpb on 21 Aug 2022
I had not poked at an animatedline object with Yair Altman's FEX submission to find hidden properties, but it turns out the X|YData arrays are pre-allocated (looks like begins with 5,000 by default) and buried several layers deep, but accessible if you know the magic decoder ring password...
Try this to get the idea and then you can adapt to your app variables, needs...
hAL=animatedline('Marker','o'); % create object, keep handle
xlim([0 1]);ylim([0 1]) % keep limits fixed so doesn't autorange on us
hold on
for i=1:5 % add some points...
addpoints(hAL,i/10,rand)
pause(0.5)
end
pause(0.5)
for i=hAL.NumPointsAdded:-1:1 % now we'll remove them in reverse order
hAL.NodeChildren.Children.XData(hAL.NumPointsAdded)=nan; % convert so won't display
hAL.NodeChildren.Children.YData(hAL.NumPointsAdded)=nan;
hAL.NumPointsAdded=hAL.NumPointsAdded-1; % update the point count to match
pause(0.5)
end
Supercially, this seems to work; what other issues may arise by munging on the object through undocumented, hidden properties only experimentation will uncover.
NOTA BENE: The X|YData arrays are initialized to zero in the object properties but no zero point is displayed initially until a specific entry at the origin were to be made via addpoints. But, in the above setting the value back to zero even though the number of points is also decremented results in the zero showing as a point at the origin; hence the use of NaN to take advantage of the builtin feature of HG that only finite values are rendered. Somewhere internally is other logic that "knows" the difference between zeros that were initial values and uses some other indicator besides only 'NumPointsAdded' to render only the first N points, but I didn't find what the key indicator is in this short investigation into the internals.
If it works to serve your purposes, well and good; but if it crashes and burns, you're on your own to figure out why and if can work around it. And, of course, just because it might work now doesn't mean the next release won't change something that breaks it.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!