473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Create an averaged matrix

L.
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.

Nov 16 '05 #1
4 2192
Hi
I am not sure if I got you right an hence that can solve your problem but
you can the random class to get random values with in your required range
.. see

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemRandomClassTopic.asp
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2
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.

"Mohamoss" wrote:
Hi
I am not sure if I got you right an hence that can solve your problem but
you can the random class to get random values with in your required range
. see

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemRandomClassTopic.asp
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3
Hi
i believe you can write the logic that would do that on your won function
reevaluating the mathematical constrains after each item generation

Nov 16 '05 #4
> 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.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
6
by: billy | last post by:
I've got a set of subclasses that each derive from a common base class. What I'd like to do is create a global array of the class types (or, class names) that a manager class can walk through in...
6
by: memocan | last post by:
#include <iostream> using namespace std; int x; //global variable matrix int main() { x= new float ; //initialize the size now }
14
by: LumisROB | last post by:
Is it possible to create matrixes with vector <vector <double >> ? If it is possible which is the element m23 ? You excuse but I am not an expert Thanks ROB
14
by: amitnanda | last post by:
Hi Guys, I have a matrix multiplication program in C that multiplies two matrices. When their size is 3*3 or 800*800, the program runs fine. But above that size, I get a "segmentation fault"....
20
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
18
by: Hypnotik | last post by:
Hello everyone. I'm writing a program which uses a class called matrix. I have written all of the different functions, constructor, etc. When I run the program I receive "Constructor", which I...
2
by: rijaalu | last post by:
I am designing a matrix class that performs addition, multicpication, substraction and division. When ever i complie the code it shows an error. include <iostream> using namespace std; class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.