how to store a changing variable matrix with the same name
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Jos (10584)
2014-2-19
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 个评论
Jos (10584)
2014-2-19
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 ...
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!