フィルターのクリア

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 Center および File ExchangeProblem-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