You Z variable is not a vector, so the max and min are not scalars. You are trying to subtract the non-scalars from the full matrix.
By default max() and min() work along the first dimension that is not of length 1; for non-vectors that is typically the first dimension, converting an M x N array into a 1 x N result. That might be what you want; if so then it would be better to explicitly specify the dimension number so that everyone immediately knows what is going on.
Are you wanting to subtract the minimum of each column from the respective column, scaling each column individually?
If what you are trying to do is scale the entire matrix according to the max and min over the entire matrix, then what you should do is
min_P = min(P.Z(:));
max_P = max(P.Z(:));
those will each be scalars, after which the rest of the code will work (unless, that is, the maximum and minimum values are equal, which we as on-lookers must point out that you have not ruled out in your problem definition.)
Best Answer