why did i get this error "Error using == Matrix dimensions must agree " ?? with MATLAB 2013a while not with MATLAB 2010b

when i am using this function: -------------- function [Am Al Amm] = regionadjacency(L)
% Identify the unique labels in the image, excluding 0 as a label.
%labels = setdiff(unique(L(:))',0);
labels=unique(L(:))';
if isempty(labels)
warning('There are no objects in the image')
Am = [];
Al = {};
return
end
Am = zeros(max(labels)); % Allocate adjacency matrix
Amm = Am;
Al = cell(1, max(labels)); % and adjacency list.
% Strategy: Dilate each labeled region and use that as a mask on the
% original labeled image. This extracts the original region plus a one
% pixel wide section of any adjacent regions. This ends up in the image 'r'
% in the code below. We then find the unique labels in 'r' ensuring the
% label of the original region and 0 are not included in the label list.
% This forms a list of region labels that are adjacent to the original
% region. We then set the entries in the adjacency list and adjacency
% matrix accordingly.
for n = labels
r = zeros(size(L));
r = L(imdilate(L==n, ones(3)));
Al{n} = setdiff(unique(r(:)), [n 0]);
Am(n, Al{n}) = 1;
% Experimental: Get strength of 'adjacency' by counting No of pixels in
% neighbouring region that is adjacent
for m = Al{n}
Amm(n,m) = sum(r(:) == m);
end
end
------------
i get this error "Error using == Matrix dimensions must agree" for this line " Amm(n,m) = sum(r(:) == m);" when i am using MATLAB 2013a but not with 2010b, so what should i do especially i need to work with 2013a??

 採用された回答

Andy
Andy 2014 年 11 月 11 日

1 投票

The only thing that makes sense is that in 2010b,
>>setdiff(unique(r(:)), [n 0]);
outputs a row vector, whereas in 2013a, it outputs a column vector. Try looking there

1 件のコメント

Doaa Adel
Doaa Adel 2014 年 11 月 11 日
thank u very much, yes, you are right. now, it works

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2014 年 11 月 11 日

コメント済み:

2014 年 11 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by