Borrar filtros
Borrar filtros

How can you update plot data from properties in an object?

3 visualizaciones (últimos 30 días)
Daniel Esser
Daniel Esser el 23 de Mayo de 2024
Respondida: Matt J el 24 de Mayo de 2024
I am new to OOP, and would like to plot changing data in an object as various methods are called that change the properties in the object. I have tried using linkdata - however it appears that this doesn't work across methods.
Is there a way to update the plot without re-plotting the figure?
sections of my code:
classdef VarStiffTDCR
properties (Constant)
F0 = [0 0 1;
0 1 0;
0 0 1];
P0 = [0 0 0]';
end
properties
%*** some properties defined here ***
end
methods
function obj = VarStiffTDCR(L,N_seg,N_pts,K_soft,K_hard,offsets)
%*** some properties initialized here ***
% Here I am plotting something based on the properties
% initialized above.
obj.figHan = figure('Name','CR Plot');
linkdata on
obj = Fkin(obj,0); % Run forward Kinematics to initialize shape.
for j = 1:obj.N_seg
indices = ((j-1)*obj.N_pts/obj.N_seg+1):(j*obj.N_pts/obj.N_seg);
plot3(obj.P(1,indices),obj.P(2,indices),obj.P(3,indices),Color=[(.9*obj.soft(j)) .1 (.9-.9*obj.soft(j))])
end
axis equal
grid on
xlabel('X [mm]');
ylabel('Y [mm]');
zlabel('Z [mm]');
end
%*** some other methods here ***
function obj = Fkin(obj,plotOn)
% This code updates P which contains the data in the plot
ds = obj.L/(obj.N_pts-1);
for j = 1:obj.N_seg
for i = ((j-1)*obj.N_pts/obj.N_seg+1):j*obj.N_pts/obj.N_seg
if i == 1
obj.BFs(:,:,i) = [0 0 1;
0 1 0;
1 0 0];
obj.P(:,i) = [0 0 0]';
else
obj.BFs(:,:,i) = obj.BFs(:,:,i-1) + ds.*[0 obj.kx(1) obj.ky(1); -obj.kx(1) 0 0; -obj.ky(1) 0 0]*obj.BFs(:,:,i-1);
obj.P(:,i) = obj.P(:,i-1) + ds*obj.BFs(1,:,i-1)';
end
end
end
if plotOn
% Here I would like the plot to update with the new values in
% P, without having to replot.
figure(obj.figHan)
refreshdata
drawnow
end
end

Respuestas (1)

Matt J
Matt J el 24 de Mayo de 2024
Consider animatedline

Categorías

Más información sobre Discrete Data Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by