Generate matrix at each iteration

Dear friend, please help me to generate a matrix 'yy' which stores matrix "xx" in each iteration.
%% direct search methods
clc;
clear variables;
delta=[2;2];
eps=10^(-3);
%% BOX EVOLUTINARY OPTIMIZATION METHOD
x0=[1;1];
% k=(delta(1)^2+delta(2)^2)^0.5;
for i=1:3
x1=x0+[1;-1];
x2=x0+[-1;-1];
x3=x0+[-1;1];
x4=x0+[1;1];
xx=[x0 x1 x2 x3 x4];
yy=xx();
f(1)=diremtd(x0);f(2)=diremtd(x1);
f(3)=diremtd(x2);f(4)=diremtd(x3);f(5)=diremtd(x4);
A=[f(1),f(2),f(3),f(4),f(5)];
k=min(A);
for j=1:5
if k==f(j)
tt=xx(:,j);
t=f(j);
end
end
x0=tt;
end
THANK YOU

 採用された回答

Image Analyst
Image Analyst 2020 年 3 月 29 日

0 投票

Instead of
yy=xx();
have
yy{i} = xx;

4 件のコメント

DEV
DEV 2020 年 3 月 29 日
dear image analyst
xx is 2*5 matrix.
this correction "yy{i} = xx;" WONT WORK
Image Analyst
Image Analyst 2020 年 3 月 29 日
Why not? It puts the whole array into the i'th cell of a cell array called yy. It should work. You asked "generate a matrix 'yy' which stores matrix "xx" in each iteration" and it certainly does that. Since what you asked is not what you want, what do you want? Do you want yy to be a 3-D array where each xx is one slice in a stack of 3 xx's? If so, declare yy before the loop:
yy = zeros(2, 5, 3);
then inside the loop, insert the current xx into slice i:
yy(:, :, i) = xx;
I can't run your code because I don't know what the diremtd() function or variable is.
DEV
DEV 2020 年 3 月 29 日
dear image analyst
thank you so much i got the matrix :).
Image Analyst
Image Analyst 2020 年 3 月 30 日
So are you ready to click the link to "Accept this answer"?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Optimization Toolbox についてさらに検索

質問済み:

DEV
2020 年 3 月 29 日

コメント済み:

2020 年 3 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by