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
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 件のコメント
Emil Åstrand
2018 年 2 月 3 日
Rik
2018 年 2 月 3 日
%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
2018 年 2 月 19 日
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 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!