Unable to perform assignment because the induces on the left side are not compatible with the size of the right side
2 views (last 30 days)
Show older comments
Mahmoud Hassan
on 23 Sep 2018
Commented: Mahmoud Hassan
on 25 Sep 2018
I am working on fingerprint minutiae algorithm and i get this error when i work on some fingerprint images. the error says Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-2 and this is my code which concerned with the error :
for ind=1:length(CentroidTermX)
Klocal=K(CentroidTermY(ind)-2:CentroidTermY(ind)+2,CentroidTermX(ind)-2:CentroidTermX(ind)+2);
Klocal(2:end-1,2:end-1)=0;
[i,j]=find(Klocal);
OrientationTerm(ind,1)=Table(i,j);
end
dxTerm=sin(OrientationTerm)*5;
dyTerm=cos(OrientationTerm)*5;
figure
imshow(K)
this part of code which find the orientation of the termination
0 Comments
Accepted Answer
Walter Roberson
on 23 Sep 2018
You extract
Klocal=K(CentroidTermY(ind)-2:CentroidTermY(ind)+2,CentroidTermX(ind)-2:CentroidTermX(ind)+2);
Klocal(2:end-1,2:end-1)=0;
so Klocal is extracted as an array with 5 rows and 5 columns, and you then zero out the lower right hand side. That leaves the top row and left column as being potentially non-zero -- Klocal(1,:) and Klocal(:,1) might be non-zero, a total of 9 different locations that are potentially non-zero.
[i,j]=find(Klocal);
That asks for the location of all of the non-zero values in the 5 x 5 array that resulted above. With 9 different locations that were not explicitly 0, you could get anywhere between 0 and 9 results. The i and j are going to be returned as column vectors in this case.
OrientationTerm(ind,1)=Table(i,j);
With ind being scalar and 1 being scalar, the left hand side names exactly one output location. The right hand side, on the other hand, names either 0, 1, 4, 9, 16, 25, 36, 49, 64, or 81 locations in Table, because when you index with two vectors of values, the output corresponds to taking all combinations of indices.
If you wanted to pull corresponding individual entries out of Table instead of rows and columns, you would use
temp = Table( sub2ind(size(Table), i, j) );
sub2ind would take those column vectors of indices and create individual indices from each corresponding row, so the above would end up designating 0 through 9 output locations.
You would then have to figure out how you wanted to store the 0 through 9 entries into OrientationTerm
Perhaps what you want is
[i,j] = find(Klocal, 1);
if ~isempty(i)
OrientationTerm(ind,1) = Table(i,j);
else
OrientationTerm(ind,1) = nan;
end
This finds one of the non-zero entries, tending with it tending to prefer to take from the first column (that you did not zero out) before it would take from the rest of the first row, because of the order that arrays are scanned.
More Answers (1)
Image Analyst
on 23 Sep 2018
Evidently the (badly-named) i and j are vectors, not single numbers.
If you had remembered to attach your variables in a .mat file, we could have done more for you.
4 Comments
Walter Roberson
on 23 Sep 2018
Saving the file and attaching it would allow other people to examine your variables and test your code.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!