필터 지우기
필터 지우기

Convert result of an optimisation problem back to original variables

조회 수: 1 (최근 30일)
Andrew Haselgrove
Andrew Haselgrove 2019년 5월 30일
I have constructed an optimisation problem with the problem-based framework, but would like to apply a range of solvers, so use prob2struct to convert the problem to the solver-based framework. In the 'Algorithms' section, it describes that, for decision variables, this is is the same as calling vars = [x(:);y(:)] on the decision variables.
My question is, how can this best be reversed? I am currently using the following:
function sol = toProblemVars(x, prob)
vars = prob.Variables;
idx = prob.varindex();
fields = fieldnames(vars);
for i = 1:numel(fields)
vars.(fields{i}) = zeros(size(vars.(fields{i})));
vars.(fields{i})(:) = x(idx.(fields{i}));
end
end
I have been trying to use deal or cell arrays to accomplish this in a neater manner, but have been unsuccessful.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by