Thread Subject: Plot figure during optimization process

Subject: Plot figure during optimization process

From: Luca Zanotti Fragonara

Date: 29 Oct, 2009 13:06:03

Message: 1 of 4

I'm performing a non linear optimization problem, using fmincon, but the problem is not that. I want to plot some graph of the function during my minimization process.

I don't want the solution at each iteration, but at each window.

I'm performing a fitting along a signal, fitting it with a polynomial, so I've as solution, a signal composed by lot of polynomial connected one by one. So, in order to do that, I'm solving a lot of fmincon problems inside a for loop. At each loop my algorithm computes the solution for just a stretch of my signal.

I can plot it at the end of my optimization process (which works fine) and i plot my new signal with the fitted signal.

If I want to plot the fitting during the optimization process, so that I see stretch by stretch how do my fitting is performing along the signal without waiting the end of the solution. So I want to plot at the beginning of the loop a figure:

par=fmincon()
est_sig=par*something;

figure,
plot(t,oldsignal),hold on
plot(t(1:length(est_signal),est_signal)

for i=1:manyloops
     par=fmincon()
     est_sig=par*something
     plot(t(someindex:someotherindex),est_signal)
end


I've tried, but it just show me AT THE END OF ALL THE MINIMIZATION PROBLEM.
So it solves the for loop BEFORE than plotting the figure.

I think that there should be an option to activate the plotting before solving all equations.

I don't mind if it is becoming very slow, because I need to monitor the solution during the process

Subject: Plot figure during optimization process

From: Luca Zanotti Fragonara

Date: 29 Oct, 2009 14:55:03

Message: 2 of 4

"Luca Zanotti Fragonara" <Luca_Zanotti@libero.it> wrote in message <hcc3vr$dsq$1@fred.mathworks.com>...
> I'm performing a non linear optimization problem, using fmincon, but the problem is not that. I want to plot some graph of the function during my minimization process.
>
> I don't want the solution at each iteration, but at each window.
>
> I'm performing a fitting along a signal, fitting it with a polynomial, so I've as solution, a signal composed by lot of polynomial connected one by one. So, in order to do that, I'm solving a lot of fmincon problems inside a for loop. At each loop my algorithm computes the solution for just a stretch of my signal.
>
> I can plot it at the end of my optimization process (which works fine) and i plot my new signal with the fitted signal.
>
> If I want to plot the fitting during the optimization process, so that I see stretch by stretch how do my fitting is performing along the signal without waiting the end of the solution. So I want to plot at the beginning of the loop a figure:
>
> par=fmincon()
> est_sig=par*something;
>
> figure,
> plot(t,oldsignal),hold on
> plot(t(1:length(est_signal),est_signal)
>
> for i=1:manyloops
> par=fmincon()
> est_sig=par*something
> plot(t(someindex:someotherindex),est_signal)
> end
>
>
> I've tried, but it just show me AT THE END OF ALL THE MINIMIZATION PROBLEM.
> So it solves the for loop BEFORE than plotting the figure.
>
> I think that there should be an option to activate the plotting before solving all equations.
>
> I don't mind if it is becoming very slow, because I need to monitor the solution during the process







I think that it has something to do with an option with the figure command. I cannot find nothing in the help, any suggestions?

Subject: Plot figure during optimization process

From: Luca Zanotti Fragonara

Date: 29 Oct, 2009 15:39:03

Message: 3 of 4

Using waitfor I've found that it plots the image, but the process get stuck until I close the figure h.

waitfor(h)

I think that I'm near the solution. Using wait I've to create I timer... Do you think that's a good idea?

Subject: Plot figure during optimization process

From: Steven Lord

Date: 29 Oct, 2009 17:12:41

Message: 4 of 4


"Luca Zanotti Fragonara" <Luca_Zanotti@libero.it> wrote in message
news:hcc3vr$dsq$1@fred.mathworks.com...
> I'm performing a non linear optimization problem, using fmincon, but the
> problem is not that. I want to plot some graph of the function during my
> minimization process.
>
> I don't want the solution at each iteration, but at each window.
>
> I'm performing a fitting along a signal, fitting it with a polynomial, so
> I've as solution, a signal composed by lot of polynomial connected one by
> one. So, in order to do that, I'm solving a lot of fmincon problems inside
> a for loop. At each loop my algorithm computes the solution for just a
> stretch of my signal.
>
> I can plot it at the end of my optimization process (which works fine) and
> i plot my new signal with the fitted signal.
>
> If I want to plot the fitting during the optimization process, so that I
> see stretch by stretch how do my fitting is performing along the signal
> without waiting the end of the solution. So I want to plot at the
> beginning of the loop a figure:
>
> par=fmincon()
> est_sig=par*something;
>
> figure,
> plot(t,oldsignal),hold on
> plot(t(1:length(est_signal),est_signal)
>
> for i=1:manyloops
> par=fmincon()
> est_sig=par*something
> plot(t(someindex:someotherindex),est_signal)
> end
>
>
> I've tried, but it just show me AT THE END OF ALL THE MINIMIZATION
> PROBLEM.
> So it solves the for loop BEFORE than plotting the figure.
>
> I think that there should be an option to activate the plotting before
> solving all equations.

Use the DRAWNOW function to force the figure window to update. Note that at
each iteration through the loop, because of the way you've written it (with
HOLD ON) you're adding in an additional line which will use up more memory.
If you want to reuse the same line, modifying its data each iteration
through the loop, store the handle of the line (which you can obtain by
specifying an output argument in your call to PLOT) and use the SET function
to change its XData and YData properties.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
plot fmincon Luca Zanotti Fragonara 29 Oct, 2009 09:09:05
rssFeed for this Thread

Contact us at files@mathworks.com