Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Dimension must agree.Where am I doing wrong?
조회 수: 1 (최근 30일)
이전 댓글 표시
o_centroid=zeros(20,2);
%all below runs in a loop where fg1 is binary image which changes after every loop.
tracking=regionprops(fg1,'basic');
n_centroid=cat(1,tracking.Centroid);
if size(n_centroid,1)< size(o_centroid,1) %here trying to get the dimensions of both v1 and v2 to be equal.
v1=o_centroid(1:size(n_centroid,1),:);
v2=n_centroid;
else
v1=n_centroid(1:size(o_centroid,1),:);
v2=o_centroid;
end
v= v1-v2;
v= (((sum(v.^2,2)).^1/2)/0.0417);
o_centroid=n_centroid;
error: error using -
matrix diemnsion must agree.
Error in line
v=v1-v2;
댓글 수: 2
Stephen23
2016년 5월 2일
Are you sure that n_centroid and o_centroid have the same number of columns/pages/... ?
답변 (2개)
Image Analyst
2016년 5월 2일
The problem could be caused by you having different number of blobs in the binary images, like 1 some images, and 3 blobs in a different image. After regionprops(), do this:
message = sprintf('This image has %d blobs in it', length(tracking));
uiwait(helpdlg(message));
Does it say that all images have the same number of blobs in it by the time it throws the error?
댓글 수: 4
Image Analyst
2016년 5월 2일
But I don't see any other way that
v= ((sum(v.^2,2)).^1/2)*0.72;
would give that error. Nothing else, other than v.^2 could possibly be considered as an index of anything. So it must be sum. What does this say if you put it right before that line of code:
which -all sum
It should show this:
>> which -all sum
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@double\sum) % double method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@uint8\sum) % uint8 method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@uint16\sum) % uint16 method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@uint32\sum) % uint32 method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@uint64\sum) % uint64 method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@int8\sum) % int8 method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@int16\sum) % int16 method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@int32\sum) % int32 method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@int64\sum) % int64 method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@single\sum) % single method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@char\sum) % char method
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\datafun\@logical\sum) % logical method
C:\Program Files\MATLAB\R2016a\toolbox\matlab\timefun\@duration\sum.m % duration method
C:\Program Files\MATLAB\R2016a\toolbox\matlab\timeseries\@timeseries\sum.m % timeseries method
If it doesn't then "sum" is the problem. If it shows that then you've probably given the wrong line of code that the error was for and you'll have to give us ALL THE RED TEXT so we can discover the true line of code that is throwing the error. Or else just give us the whole m-file and dependent m-files.
louis rassinfosse
2016년 5월 2일
v1=o_centroid(1:size(n_centroid,1) ,:);
v2=n_centroid;
i think your mistake is here, try: v1 = o_centroid(1:size(n_centroid,1));
댓글 수: 3
louis rassinfosse
2016년 5월 2일
what about your o centroid ? 2 columns as well ? because you cannot sum a 1 column with a 2 column matrix. However, if both have 2 columns, try to find your error by opening v1 and v2 separatly and looking at how they have been changed compared to n and o centroid
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!