Animated line and moving markers with different, changing colors
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Julian Holst
el 29 de Ag. de 2022
Editada: Julian Holst
el 29 de Ag. de 2022
I want to have 100 markers (hypothesis) that move and change colors based on predetermined values.
I want to use it alongside my animatedline.
Here is an example code I made so you can try it out yourself:
x_est = randn(1,10000)+(0:0.01:99.99);
y_est = randn(1,10000)+(0:0.01:99.99);
x = randn(100,10000)+(0:0.01:99.99); % Hypothesis x-Data
y = randn(100,10000)+(0:0.01:99.99); % Hypothesis y-Data
w = rand(100,10000); % Hypothesis weights
figure(21)
hAL = animatedline; % Handle
hAL.Color = 'r';
handle = gca;
c = [ones(100,1)-w(:,1) zeros(100,1) w(:,1)]; % Colors of each hypothesis
hS = scatter(handle, x(:,1), y(:,1), 6, c, 'filled'); % Show hypothesis
xlim([0 100])
ylim([0 100])
for i = 1:1:10000 % Animate
addpoints(hAL, x_est(i), y_est(i));
c = [ones(100,1)-w(:,i) zeros(100,1) w(:,i)];
set(hS,'xdata', x(:,i), 'ydata', y(:,i),'CData',c)
drawnow;
pause(0.001)
end
I get the following error: "Error using matlab.graphics.animation.AnimatedLine/addpoints Value must be a handle."
Though it works when only using the animatedline or only scatter for the animation. But never when combined.
Do you know how to get rid of this error? Any suggestions for improvements on efficiency are also appreciated.
0 comentarios
Respuesta aceptada
Steven Lord
el 29 de Ag. de 2022
When you call scatter, since you didn't turn hold on MATLAB will clear all the children from the axes. This includes your animatedline object. To avoid the problem, use hold on to prevent scatter from removing the children.
Más respuestas (0)
Ver también
Categorías
Más información sobre Animation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!