Create an averaged matrix

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I need to generate random Matrices (say of size 5*5), each with an
average of X (say X=0.5), but with different values’ range. One
matrix should have values in the range of 0-1, while the second one’s
values should have a low variance and lie in the range of (X-1) –
(X+1). The matrices represent a visual scene and the values represent the
Gray-level intensities.

I'm using Matlab 6.5 but currently looking for any algorithm that can solve
this problem in any lang.

I was also wondering how I can control the difference between each
value and its neighbours within the matrix. I would like the
difference to be not bigger than a specific constant value.

This is really urgent so any help will be appreciated...

Thanks in advance,
L.
 
Hi,

Thanks but this is still dosn't solve the whole problem which is- how to
generate a Matrix with a predefined average. for example: create a 5X5
matrix, with a range values lof 0-1 and an average of 0.5 (the average of the
matrix should be 0.5).

Cheers,
L.
 
Hi
i believe you can write the logic that would do that on your won function
reevaluating the mathematical constrains after each item generation
 
I need to generate random Matrices (say of size 5*5), each with an
average of X (say X=0.5), but with different values' range. One
matrix should have values in the range of 0-1, while the second one's
values should have a low variance and lie in the range of (X-1) -
(X+1). The matrices represent a visual scene and the values represent the
Gray-level intensities.

I'm using Matlab 6.5 but currently looking for any algorithm that can
solve
this problem in any lang.

I was also wondering how I can control the difference between each
value and its neighbours within the matrix. I would like the
difference to be not bigger than a specific constant value.

This is really urgent so any help will be appreciated...

I've never tried to do this sort of thing with a 2-d matrix, so you'll have
some work to apply these ideas to your situation with your constraints, but
here are some approaches:

To enforce a matrix-wide average, you could iterate over the array, set each
item to some random value. Along the way, keep a sum of all the items.
When you're done, you can compare the sum to what the sum _should_ be, for
whatever constraints you're trying to enforce. The difference between the
sum and what the sum should be represents the total error in your matrix.
Divide that total error by the number of items in the matrix, and then
subtract that much from every item. Basically, you make a random matrix,
and then shift the whole matrix up or down by exactly enough to make the
average come out where you want.

As far as enforcing a maximum difference between matrix elements, I think
you're going to have to iterate over all the elements, and for each one,
test it against its neighbors. If you find a pair of elements that is too
different, you can add and subtract some amount from each one in order to
bring them into compliance with your constraints. Depending on what
statistics you may be trying to enforce on the matrix as a whole, this
solution may not be good for you. You might also investigate swapping
elements around within the matrix to fix these situations.
 
Back
Top