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!