store matrix and the row matrix that corresponds to the smallest distance?

2 ビュー (過去 30 日間)
JAGADEESH JAGA
JAGADEESH JAGA 2017 年 2 月 2 日
編集済み: Andrei Bobrov 2017 年 2 月 3 日
f=[2 1 1]; m=3; A=[ 1 0 0]; B=[1 1 0]; D=B-A; d1=m*A; for X=1:1:m+1 C=d1+D*(X-1); c=transpose(C); h(X)=f*c L=min(h) end I need the matrix "C" corresponding to the minimum value of "h" i.e if minimum value h is 6 then the matrix is [3 0 0] then into a coloumn MATRIX i.e[3; 0; 0]

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2017 年 2 月 2 日
編集済み: Andrei Bobrov 2017 年 2 月 3 日
f =[2 1 1];
m =3;
A =[ 1 0 0];
B =[1 1 0];
D =B-A;
d1 =m*A;
C =bsxfun(@plus,d1,(0:m)'*D);
h = C*f';
[~,ii] = min(h);
out = C(ii,:).';

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by