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!

답변 (1개)

Rik
Rik 2018년 2월 3일

0 개 추천

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

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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

질문:

2018년 2월 3일

댓글:

Rik
2018년 2월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by