Graph handles in loops

20 visualizaciones (últimos 30 días)
Michael Pilgrim
Michael Pilgrim el 19 de Mayo de 2020
Comentada: Geoff Hayes el 19 de Mayo de 2020
I am trying to animate several objects at once and can not figure out how to make it work the way I need it to. So far this is the general stucture I have figured out.
What do I need to do different to make this work? Also is there a way to generate the handles without typing them out?
handles = [ "h1", "h2", "h3", ... ];
for j = 1:numObjects
handles(j) = plot(stuff(1));
end
for i = 2:numSteps
for j = 1:numObjects
handles(j) = set(stuff(i));
end
pause timeStep
end

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 19 de Mayo de 2020
Editada: Geoff Hayes el 19 de Mayo de 2020
Michael - since you have already created the handles with the code
for j = 1:numObjects
handles(j) = plot(stuff(1));
end
you will then need to update them in your other loop (rather than re-assigning something to the handles array). Try this
for i = 2:numSteps
for j = 1:numObjects
set(handles(j),'PropertyName', Value);
end
pause timeStep
end
where you need to "fill in" what (one or more) property names and values that you are updating.
  2 comentarios
Michael Pilgrim
Michael Pilgrim el 19 de Mayo de 2020
Ok, probably should have included this in the question, but I am not even making it out of the first loop.
Error using string
Conversion to string from
matlab.graphics.primitive.Line is not possible.
Error in animateGate (line 60)
h(j) = plotBlochVector(GA(T(1)) * ket);
Geoff Hayes
Geoff Hayes el 19 de Mayo de 2020
Michael - sorry, I missed that first line
handles = [ "h1", "h2", "h3", ... ];
There is no need to assign strings here and so that is why there is the error - you have a string array, and then in the loop you are assigning the graphics object handles (which are doubles). Just replace this line with
handles = []; % or handles = zeros(numObjects);
and try again.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by