필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Daniel Esser
Daniel Esser 2024년 5월 23일
답변: Matt J 2024년 5월 24일
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

답변 (1개)

Matt J
Matt J 2024년 5월 24일
Consider animatedline

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by