If your unique values aren't sequential, you should use unique to get all those values:
[U, ~, upos] = unique(m);
umat = reshape(upos, size(m));
% Note that U(umat) == m.
Now, umat is neat as it has sequential unique integer values and you can work on it instead of original matrix (use gnovice's solution). Or, you can use U instead of this 1:N, again his answer for "matlab-y" approach.
Though, I would likely use a loop here. It shouldn't have significant performance difference.
Now, this approach has one problem - it goes through the matrices MANY times. Here, I could imagine a workaround along the lines:
foundInds = m(1);
logMats = cell(1);
logMats{1} = false(size(m));
for i = 1 : numel(m)
anyFound = false;
for j = 1 : length(foundInds)
if (m(i) == foundInds(j))
anyFound = true;
logMats{j}(i) = true;
break;
end
end
if ~anyFound
% Add the new element.
foundInds(end+1) = m(i);
logMats{length(foundInds)} = false(size(m));
logMats{length(foundInds)}(i) = true;
end
end
(you need to at least make it less dumb by not changing foundInds and logMats size for every new element by the initial guess of number of unique elements)
However, despite the code goes through the elements only once and does the minimum amount of work needed in theory ... it simply doesn't work well in the current form - it only outperforms gnovice's solution in case you have tons of possible values, yet small matrices (unique works the best here).
m1,m2, etc. You'll end up having to programatically generate variable names, which is a nightmare. It is better to use a cell array. You'd end up, for example, withm{1},m{2}, etc. Now writing the above in a loop is easy. But I'm sure you'll get more clever solutions.uniqueto select for which integers to create a logical matrix? Or are you looking for a vectorized approach? (Loops in MATLAB are actually quite fast nowadays).splitapplyin combination withuniquebut without success so far.