How to automatize plot redraw for different initial data?

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!

Risposte (1)

Rik
Rik il 3 Feb 2018
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 Commenti

I'm not familiar using guidata and keypressfcn, could you please elaborate this answer?
Have you read the documentation for guidata or KeyPressFcn?
%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.
Did my answer help you? If so, please mark it as accepted answer. If not, feel free to comment here with any remaining question.

Accedi per commentare.

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Tag

Richiesto:

il 3 Feb 2018

Commentato:

Rik
il 19 Feb 2018

Community Treasure Hunt

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

Start Hunting!

Translated by