필터 지우기
필터 지우기

How to compare pixel co-ordination using a for loop ?

조회 수: 1 (최근 30일)
Piyum Rangana
Piyum Rangana 2017년 5월 24일
답변: Jan 2017년 5월 26일
Here is my MATLAB code.
for j = 1 : numberOfRegions
thisBoundary = boundaries{j};
x = thisBoundary(:, 1);
y = thisBoundary(:, 2);
for j2 = 1 : numberOfRegions2
thisBoundary2 = boundaries2{j2};
x2 = thisBoundary2(:, 1);
y2 = thisBoundary2(:, 2);
if(x2==x)
if (y2 == y)
U = x2;
V = y2;
end
end
end
end
In this code I tried to compare boundary pixel co-ordinations(x,y) of two masks which I already obtained. But when it comes to the if condition it gives following error. I want to obtain the matched pixel co-ordinations and store them separately. how can I fixed that?
_ Matrix dimensions must agree. Error in (line 130) if(x2==x)_
  댓글 수: 3
Piyum Rangana
Piyum Rangana 2017년 5월 24일
Yes it is not equal. How can I check whether a pixel co-ordination of first boundary in a second boundary with this code then ?
Sanket Karnik
Sanket Karnik 2017년 5월 26일
I understand that you are getting "Matrix dimensions must agree" error when you try to compare 2 matrices. As KSSV mentioned this error message suggests that you are trying to perform matrix operations on matrices of unequal dimension. If you are comparing two matrices then it is very important that both matrices are of same size. In order to answer your next question, please post here the data you are using so that we can try to advice you by referring to that data.

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

채택된 답변

Jan
Jan 2017년 5월 26일
You have to define, what should happen in x2==x. What do you want to compare? x2==x is an elementwise comparison: Either both arrays need the same size or one is a scalar. Internally the IF-condition is converted to a scalar, as needed:
if all(reshape(x2==x, 1, [])) && ~isempty(x2==x)
This must still fail. But it demonstrates, that there is more to define than just using the == operator. Perhaps you want:
if any(ismember(x2, x))
or
if all(ismember(x2, x))
or
if any(ismember(x, x2))
or what ever. You have to explain this, before a specific solution can be suggested.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by