how to store a changing variable matrix with the same name

2 views (last 30 days)
Hello,
I have a row (1x8) of variables named Pars. The variables of Pars are changed by a function (fminsearch). I want to save Pars into another matrix each time one of the variables is changed. I've tried to use an output-function within fminsearch but this doesnt work.
However, within my minimization function (the function that fminsearch tries to minimize) I can write display(Pars) and the variables of Pars are displayed each time one of them is changed. I want to store the displayed variables in a matrix so each time one of the variables is changed they are stored in a new row.
I've tried something like this (this was recommended by someone) but it doesnt work. I also want to save the data to the workspace.
data(1:length(Pars), and+1)=Pars
Can anyone help me? Thanks in advance!
greetings Boudewijn

Answers (1)

Jos (10584)
Jos (10584) on 19 Feb 2014
Something like this?
data = nan(0,8)
pars = fminsearch(...)
if IsChanged(pars),
data(end+1,:) = pars ;
end
IsChanged is a function (or expression) that you have to define yourself.
  1 Comment
Jos (10584)
Jos (10584) on 19 Feb 2014
btw your pars is a row vector with 8 columns, but your expression " data(1:length(Pars), end+1)=Pars " suggests that you want to store it as the last column. This does not add up ...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!