필터 지우기
필터 지우기

matric "c" and "d" out of for loop and c row matrix corresponding to minimum distance

조회 수: 3 (최근 30일)
m=2
T=[1 0 0; 0 (1/sqrt(2)) (1/sqrt(2))];
V1=0.956
V2=2.4
A=[ 1 0 0];
B=[1 1 0];
D=B-A;
d1=m*A;
for X=1:1:m+1
c(x,:)=d1+D*(x-1)
Vndq=T*c(x,:)';
Vnq=Vndq(1,1)
Vnd=Vndq(2,1)
d(x)=abs(V2-Vnq)+abs(V1-Vnd)
end
in the code given minimum distance is
d =[1.3560 0.6489 0.8582]
and
C =
2 0 0
2 1 0
2 2 0
c row matrix 2 1 0 of the minimum distance 0.6489 should be obtained

채택된 답변

Stephen23
Stephen23 2017년 2월 4일
편집: Stephen23 2017년 2월 4일
Here is a simpler version of your code:
m = 2;
T = [1,0,0;0,(1/sqrt(2)),(1/sqrt(2))];
V1 = 0.956;
V2 = 2.4;
c = zeros(m+1,3);
c(:,1) = m;
c(:,2) = 0:m;
Vndq = T*c.'
d = sum(abs(bsxfun(@minus,[V2;V1],Vndq)),1)
Use min to get the closest value:
>> [val,idx] = min(d)
val =
0.64889
idx =
2
>> c(idx,:)
ans =
2 1 0

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by