The whole script does not make much sense:
First thing: forget about length, it's not a good function and often used improperly. Use size for matrices, numel for vectors. Much better and faster
The only reason one would use find(x == min(x)) is if one expect that the minimum value is repeated several times. If not,
is much simpler. So, assuming that there are repetitions of the minimum values, the find will return several locations. The rows are assigned to row(:, p). Several things can happen there:
- row does not yet exist. It is created to have as many rows as elements returned by find. All is fine.
- row does exist and has the same numbers of rows as the number of elements returned by find. The new values are put into column p of row. All is fine.
- row already exists but find return more or less elements than its number of rows. The assignment will fail with dimension mismatch error. Considering that there is no guarantee that for each p you'll have the same number of minimum elements, you're bound to hit this error.
Going back to find, the columns are assigned to col(p) which can only receive one element. Whenever find returns more than one, you'll get a dimension mismatch error.
So, before we had row(:, p), now we have row(p). You're not consistent and not even accessing the values you've just stored in row. This makes zero sense.
I have no idea what your real intent is, you haven't said what the code is supposed to do and you did not comment the code (hint!), so it's impossible to say what the correct code should be.