Azzera filtri
Azzera filtri

Animated line and moving markers with different, changing colors

12 visualizzazioni (ultimi 30 giorni)
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
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)
I get the following error: "Error using 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.

Risposta accettata

Steven Lord
Steven Lord il 29 Ago 2022
I advise you not to use handle as a variable name, as it already has a meaning in MATLAB.
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.

Più risposte (0)


Scopri di più su Animation in Help Center e File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by