Custom Plot Function of Subplots in Optimizaion

1 Ansicht (letzte 30 Tage)
Pengfei
Pengfei am 23 Jun. 2016
Bearbeitet: Pengfei am 23 Jun. 2016
Hi, in my customized plot function, each time one function is called for the current x, outputting a 1*3 vector f3. I want to show the history of all the 3 values in f3. Below is the code. It's not working properly, as directly after the very first iteration, the 3-by-1 subplots were refreshed to a 1-by-1 axes, and further reset data operations cannot catch the settings. Thanks a lot for the help!
function stop = optimplotx_my(x,optimValues,state,varargin)
stop = false;
switch state
case 'iter'
% Reshape if x is a matrix
x = x(:);
xLength = length(x);
f3 = func(x); % f3 : 1 by 3
iteration = optimValues.iteration;
if optimValues.iteration == 0
subplot(3,1,1);
sub1 = plot(iteration,f3(1),'kd');
set(sub1, 'Tag', 'axes1')
subplot(3,1,2, 'Tag', 'axes2');
sub2 = plot(iteration,f3(2));
set(sub2, 'Tag', 'axes2')
subplot(3,1,3, 'Tag', 'axes3');
sub3 = plot(iteration,f3(3),'bd');
set(sub3, 'Tag', 'axes3')
else
subplot(3,1,1)
sub1 = findobj(get(gca,'Children'), 'Tag','axes1');
newX = [get(sub1,'Xdata') iteration];
newY1 = [get(sub1,'Ydata') f3(1)];
set(sub1,'Xdata',newX, 'Ydata',newY1);
subplot(3,1,2)
sub2 = findobj(get(gca,'Children'), 'Tag','axes2');
newX = [get(sub2,'Xdata') iteration];
newY2 = [get(sub2,'Ydata') rgb(2)];
set(sub2,'Xdata',newX, 'Ydata',newY2);
subplot(3,1,3)
sub3 = findobj(get(gca,'Children'), 'Tag','axes3');
newX = [get(sub3,'Xdata') iteration];
newY3 = [get(sub3,'Ydata') f3(3)];
set(sub3,'Xdata',newX, 'Ydata',newY3);
end
end

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by