plot data into a while lopp without storing the data

1 visualización (últimos 30 días)
mikel lasa
mikel lasa el 20 de En. de 2022
Editada: mikel lasa el 26 de En. de 2022
Hello,
I have a while loop that iterates 2500 times and in each loop I get 3 arrays of 6x1. I dont want to store the data for each iteration, only plot the actual data and keep updating the same plot... is that possible??
Thanks in advance
  2 comentarios
Ankit
Ankit el 20 de En. de 2022
yes it is possible.. how your code looks like?
mikel lasa
mikel lasa el 20 de En. de 2022
%% INIT
clear all;
close all;
clc;
%% loop img
img = imread('bucle_PD.PNG');
imshow(img)
%% Load paths and regressor functions
% load paths from .MAT file
paths=load('robot_path.mat','pos','vel','acc'); %
n=6;
for i=1:n
pos(i)=paths.pos(1,i);
vel(i)=paths.vel(1,i);
acc(i)=paths.acc(1,i);
end
% load regressor functions
fregs=load('fregs.mat','fregFric','fregG','fregCentrCorG','fregCentrCor','fregM');
fregFric=fregs.fregFric;
fregG=fregs.fregG;
fregCentrCorG=fregs.fregCentrCorG;
fregCentrCor=fregs.fregCentrCor;
fregM=fregs.fregM;
%% set boundaries
%T0=0;
Hzloop = rateControl(200);
%tloop=0.005; %loop time rate
Hztdynamics = rateControl(50);
%tdynamics= 0.02; %dynamic parameters refresh rate
Kp=1;
Kv=1;
deltaT=0.004;
%% Loop computation
E1=[];
Efeedback=[0;0;0;0;0;0];
E2=[0,0,0,0,0,0];
k=0;
qs=[];
while k <= 10
k= k+1;
for i=1:length(acc{1})
% comienza desde estado 0 de robot (q=0, qd= 0, qdd=0)
% E2 corresponde al calculo de la salida del robot*dinamica
E2=fregCentrCorG(vel{1}(1,i),vel{2}(1,i),vel{3}(1,i),vel{4}(1,i),vel{5}(1,i),vel{6}(1,i),pos{2}(1,i),pos{3}(1,i),pos{4}(1,i),pos{5}(1,i),pos{6}(1,i))+fregG(pos{2}(1,i),pos{3}(1,i),pos{4}(1,i),pos{5}(1,i),pos{6}(1,i))+fregFric(vel{1}(1,i),vel{2}(1,i),vel{3}(1,i),vel{4}(1,i),vel{5}(1,i),vel{6}(1,i));
%calculo de E1
for j=1:n
%Efeed es la primera resta que viene del feedback
Efeedback(j,1)=(pos{j}(1,i)-Efeedback(j,1));
E1(j,1)=acc{j}(1,i)+(vel{j}(1,i)-Efeedback(j,1))*Kv+Efeedback(j,1)*Kp;
end
%calculo de la matriz M
EM= fregM(E1(2,1),E1(3,1),E1(4,1),E1(5,1),E1(6,1));
% calcular los torques
torque=EM*E2;
%con el torque calculado, calcular la thetadd de salida
qdd= inv(EM)*(torque-E2);
%calcular thetad siguiente
for indx=1:n
qds=vel{indx}(1,i)+deltaT*qdd;
% calcular thetas
qs(indx,1)=pos{indx}(1,i)+deltaT*vel{indx}(1,i);
end
%cerrar el bucle
end
end
I want to plot just the las 3 variables:
qdd
qds
qs

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 20 de En. de 2022
If you want each new iteration to replace previously plotted results:
i = 0
while i < 2500
% do stuff
hold off
plot(x)
hold on
plot(y)
plot(z)
drawnow()
i = i+1;
end
If you want each new iteration to add to the previously plotted results:
hold on
i = 0
while i < 2500
% do stuff
plot(x)
plot(y)
plot(z)
drawnow()
i = i+1;
end
  3 comentarios
Voss
Voss el 21 de En. de 2022
The line:
plot(i,qs(1,1))
plots one point. What happens if you replace that with this:
plot(qs(:,1))
or perhaps this:
plot(i*ones(n,1),qs(:,1))
Try those and see if it's more like what you want.
(And if you attach the necessary mat files, I'll be able to run the code and provide more useful help.)
mikel lasa
mikel lasa el 26 de En. de 2022
Editada: mikel lasa el 26 de En. de 2022
Hello,
sorry for the late asnwer, I was out for a couple of days.
I've tried to apply your plot lines but no success. I've attached my mat files to help you.
EDIT: using plot(i*ones(n,1),qs(:,1)) works, dont know why but using the default settigns it doesnt plot anything.
I tried to add 'o' to the plot (i*ones(n,1),qs(:,1),'o') and works now
Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Visual Exploration en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by