How to automatize plot redraw for different initial data?
Mostrar comentarios más antiguos
Hello,
I have a code drawing three different plots in one figure, consisting of three for loops, for some set initial data. The initial data is initialized at the beginning of the section. I would like to, for each time I hit the space key for example, redo the whole segment but change the initial data.
I was thinking about another for loop outside the inner threes but this feels like looking for trouble. I have been looking at functions that could do this but no luck.
My code looks like this:
initial values... d=20e-6
for th=0:1:s
i=eye(2)
for n=50:-1:1
i=i*function(n,th,initial data,d)
end
end
plot(th,I,'b')
hold on
next loop
So when this ends I'd like to press a key, and make d=19e-6 and redo the code, plot, until I'm good. Thanks for answers!
Respuestas (1)
Rik
el 3 de Feb. de 2018
0 votos
Just put this code in a function. You can then use guidata to store and load that initial value, and set it as the KeyPressFcn of your figure.
3 comentarios
Emil Åstrand
el 3 de Feb. de 2018
Rik
el 3 de Feb. de 2018
%Your function header should be like this:
function your_keypress_callback(source,eventdata)
handles=guidata(source);
d=handles.d;
%Your initializing function should contain something like this:
handles=struct('fig',gcf,'d',d);
guidata(handles.fig,handles)
set(handles.fig,'KeyPressFcn',@your_keypress_callback)
Preferably you would also include the handles to your subplot axes, so you can easily replace plots, instead of having to recreate the axes, but that is a next step.
Rik
el 19 de Feb. de 2018
Did my answer help you? If so, please mark it as accepted answer. If not, feel free to comment here with any remaining question.
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!