a=; b=; for i=1:length(l) [m n]=find(R==l(i)); a(i)=m; b(i)=n; end In an assignment A(I) = B, the number of elements in B and I must be the same.
In this code l is a column vector and R a matrix containing all elements of l and more.This 'for loop' is contained in yet another 'for loop'.Now for the first couple loops in the bigger 'for loop' no error is given.Then halfway through, the error shown above is displayed. I cannot understand why this happens, and why the error is not given all the time.
No products are associated with this question.
What is likely happening is that at first, your find() command is finding exactly one instance of R==l(i), and therefore there is one value of [m,n]. But if there are multiple instances of R==l(i), then there is a vector of [m,n] values, and that cannot be assigned to a(i) and b(i), which are scalar elements.
You should be able to breakpoint into your code and see for which value of i this is happening.
That's NOT going to give you what you think it will. Your index will ALWAYS be either empty or just one. You're getting the error when it's empty (no match). It's not going to give you a list of indexes where l matches R. Even if you do put in a check for empty, your a and b will just be 1 or 0, not the indices.
[a b] = find(R == l);
and do away with the for loop altogether, and get the indices like you want.
Or if you really want a binary comparison (match or no match), simply do
binaryMap = l == R;