I have a matrix (population
, with 8 columns and 100 rows) of positive and negative numbers.
I want to create a matrix where each row has 8 real numbers which satisfy:
- All numbers are in the range [0,1]
- The sum of numbers in each row should be equal to 1
I wrote the code below. I tried to normalize the number in the rows but it doesn't work because the result contains negative numbers.
population(:,1:8) = bsxfun(@rdivide,population(:,1:8).',sum(population(:,1:8).')).';
How can I fix this?
For example, the input [1 -2 3]
should give the output [0.375 0 0.625]