How to compare pixel co-ordination using a for loop ?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!