distance

Hi, I'm trying to find middle distance. We did it this way
c1=handles.centroids(:,1);
c2=handles.centroids(:,2);
d1=sqrt(((xi(:,1)-c1))^2+(yi(:,1)-c2)^2);
d11=sqrt(((xi(:,2)-c1))^2+(yi(:,2)-c2)^2);
vz1=(d1+d11)/2;
str = ['strední vzdalenost v prvním okně je ', num2str(d1), ' pixelu.'];
disp (str);
but my voice is a mistake vcem Does anybody know the problem?
??? Error using ==> mpower
Inputs must be a scalar and a square matrix.
Thank you very much

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 4월 11일

1 개 추천

use .^
d1=sqrt(((xi(:,1)-c1))^2+(yi(:,1)-c2)^2);
d11=sqrt(((xi(:,2)-c1)).^2+(yi(:,2)-c2).^2);
on comment
d = sqrt((xi-c1).^2+(yi-c2).^2);
vz1 = mean(d);

댓글 수: 5

Adam
Adam 2012년 4월 11일
after treatment system reports this error:
Attempted to access xi(:,2); index out of bounds because
size(xi)=[2,1].
Jan
Jan 2012년 4월 11일
@Adam: The error message is clear: You try to access a not existing element of the array xi. Because you did not explain or show how xi is created, it is impossible to give any advice.
Adam
Adam 2012년 4월 11일
ginput create using the values xi yi, which is also at the function as the rows to calculate the distance.
hold on
n=0;
[xi,yi,but] = ginput(2);
% plot(xi,yi,'g*');
n = n+1;
x(:,n) = xi;
y(:,n) = yi;
plot(xi,yi,'r*');
%xy(:,n) = [xi;yi];
hold off
Adam
Adam 2012년 4월 13일
Well here is the complete code as I realized. When inserting one point so it works, for more no:
file_name ='bw.bmp';
BW = imread(file_name);
imshow (BW)
s3 = regionprops(BW, 'centroid');
centroids3 = cat(1, s3.Centroid);
hold on
plot(centroids3(:,1), centroids3(:,2), 'r*')
hold off
hold on
n=0;
[a,b,but] = ginput(2);
n = n+1;
x(:,n) = a;
y(:,n) = b;
plot(a,b,'r*');
hold off
c1=centroids3(:,1);
c2=centroids3(:,2);
d1=sqrt(((a-c1)).^2+(b-c2).^2);
d11=sqrt(((a-c1))^2+(b-c2).^2);
vz1=(d1+d11)/2;
str = ['strední vzdalenost v prvním okně je ', num2str(vz1), ' pixelu.'];
disp (str);
can be downloaded from the link picture:
http://www.ulozto.cz/xAEvHHw/bw-bmp
Adam
Adam 2012년 4월 13일
I had the problem resolved but it is not very elegant solution ... I'll happy with any help.
thank you

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

질문:

2012년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by