473,738 Members | 5,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2212
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/
frlrfSystemRand omClassTopic.as p
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/
frlrfSystemRand omClassTopic.as p
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
3805
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 complex operator, I get stuck. Here's a brief description what I want to do. I want to simulate a matrix (2D array) from a 1D array. so what I have so far is something like this: class Matrix
6
2371
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 its constructor and instantiate one of each of the class types in this global array. So, it's almost like the global array has to hold data types as opposed to data. Basically, I currently have to add the items manually 1 at a time.
6
6581
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
2665
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
4970
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". I need this huge size as part of my assignment.
20
5238
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 used various techniques ( loop unrolling, loop jamming...) and tried some matrix libraries : newmat (slow for large matrix) , STL (fast but ..not usefull) , hand coding (brain consuming...), and recently Meschach...
1
7972
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 compiled and run without any erros but the second program has a run time error when the function return from allocate and the ptr become NULL. How to fixed this? Second Program: /* Best Method to allocate memory for 2D Array because it's ...
18
2477
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 placed in the constructor, and then the program crashes. I have no clue where my problem is. The matrix is for size 2x2 up to 10x10, and it must be square. Below is the code: #include <iostream>
2
2666
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 matrix{ public: matrix();
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.