c row matrix corresponding to the minimum value of the distance of the matrix

1 回表示 (過去 30 日間)
m=3;
t=[1 0 0; 0 (1/sqrt(2)) (1/sqrt(2))];
v1=0.24;
v2=0.956;
a=[ 1 1 0];
b=[0 1 0];
p=b-a;
d1=m*a;
for x=1:1:m+1
c=d1+p*(x-1)
f=transpose(c);
vndq=t*f;
vnq=vndq(1,1);
vnd=vndq(2,1);
d(x)=abs(v2-vnq)+abs(v1-vnd)
n=min(d)
end
In the given code c row matrix corresponding minimum value of d matrix must be output if the d changes corresponding c row matrix should be abtained to that minimum distance using for loop

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 2 月 3 日
編集済み: Andrei Bobrov 2017 年 2 月 3 日
m = 3;
t = [1 0 0; 0 (1/sqrt(2)) (1/sqrt(2))];
v1 = 0.24;
v2 = 0.956;
a = [ 1 1 0];
b = [0 1 0];
p = b - a;
d1 = m * a;
x = (0 : m)';
c = bsxfun(@plus, d1, x * p);
v = t * c';
d = sum(abs(bsxfun(@minus,[v2;v1], v)));
[~,n] = min(d);
out = c(n,:);
with loop for..end :(
m = 3;
t = [1 0 0; 0 (1/sqrt(2)) (1/sqrt(2))];
v1 = 0.24;
v2 = 0.956;
a = [ 1 1 0];
b = [0 1 0];
p = b - a;
d1 = m * a;
n0 = numel(d1);
out = zeros(1,n0);
ii = 0;
c = zeros(m+1,n0);
n = inf;
for x = 1:m + 1
c(x,:) = d1 + p * (x - 1);
vndq = t * c(x,:)';
d(x) = sum(abs([v2;v1] - vndq));
if d(x) < n
out = c(x,:);
ii = x;
n = d(x);
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by