- You have capital X and low case x. Don't mix them.
- size(X) will return two values for scalar, vector or 2-D matrix. The statement "for j=1:1:size(X)" will use the first value returned by size(X) function. But it will be better if you specify it like size(X,1) or size(X,2) depending on your need.#
Controlling X variable when using Fmincon
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have a problem where I want to reference previous iterations of Fmincon to use in current function evaluations. For example, the function looks something like this in pseudocode:
[log_value] = function (params)
for i=1:1:num_days
temp_indicator_vector = indicator_vector{1,i};
for j=1:1:size(X) if indicator_vector(j) == 0 x(j) = x_old(j) end end
.... calculate log_value based on x
So, the question is how do I save the previous iteration of x as x_old so that I can use it in the current? I know I can write each iteration to the disk and read it back into Matlab, but I am hoping to do it in memory to keep the computation as fast as possible.
Any help would be appreciated,
Ed
댓글 수: 0
답변 (2개)
Fangjun Jiang
2011년 9월 19일
After the iteration, just use x_old=x;
Do you know that you can assign a matrix to another matrix, as long as they are in the same size? Like this:
x_old=1:10;
x=rand(1,10);
x_old=x;
Two other things,
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!