Link to home
Start Free TrialLog in
Avatar of ZURINET
ZURINET

asked on

Isolating Matrix vector value

Hi all

I have a matrix (3 * 2) with 6 coordinates..
0 0
0 1
1 0
1 1
2 0
2 1

How can I isolate a given coordinate from the loop below..
Example I need to loop through all the coordinate .. exlusive coordinate 3 which have x,y = (1 0)

Thanks in Advance
for(int i=0; i<Matrix.length; i++){
do some calculation   
}

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

if(i == 3)

should do it shouldn't it?
for(int i=0; i<3; i++){
for(int j=0; j<2; j++){
if(i==1 &&  j==0)continue;
//Matrix[i][j] - do somthing
}
}

Open in new window

Sorry

if(i == 2)

in oned-dimensional array it would be
if(i== 2) continue;

if you need to exclude values x,y = m,n
and you have them in one dimeninonal
array thane you shoul exlude
element
m*2 + n
Avatar of ZURINET
ZURINET

ASKER

Hi all

If I do this

for(int i=0; i<Matrix.length; i++){
Here I don't know exactly which position it could be...
I will be passing a vector with [x, y] coordinates
Hence : example  : gene[x,y] -- coordinates unknow at run time (Dynamic coordiates)

}

so this is the code if theye are stored in  one-dimensional array:

to exclude pair (m,n):
for(int i=0; i<6; i++){
if(i == (m*2+n))continue;
//do somthing with matrix[i]...
}

Open in new window



for(int i=0; i<6; i++){
if((String)matruix[i].get(0).equals("1") && matrix[i].get(1).equals("0"))conrtinue;

//do somthing with matrix[i]...
}

Open in new window

By passing a "vector" - do you mean it is array ot it is an ArrayList - how do you hold these
values x and y ?
So Matrix as I understand is an array,
but waht are elements of that array - are they two-element arrays themslevles
or are they Vector objcets or ArrayList - do you have some
code before - how you store them?
Avatar of ZURINET

ASKER

I have a matrix (3 * 2) with 6 coordinates..
0 0
0 1
1 0
1 1
2 0
2 1

Coordinates in mathmatics is just a pointer to some value.. or an address..
This address holds some value..

If I have coordinates
0 1.. (the value may be a string and Integer..)
But the coordinates is just a key or a pointer..

hence if I do
for(int i=0; i<Matrix.length; i++){
}
I will going through the lenght of the matirx..  1....n
I have a method.. I can use get the coordinates .. getX and getY.
This is common in Dimentional array..

Avatar of ZURINET

ASKER

I am looking for a way to tell the loop to skip some pointer .. or coordinate x,y in the dimention
for(int i=0; i<Matrix.length; i++){
if(Matrix[i].getX() == 1 && Matrix[i].getY() ==0)continue;
//do somthing with matrix[i]...
}

Open in new window

Avatar of ZURINET

ASKER

I thought.. so..
Will give it a try.. and get back to your

Thanks
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You need to iterate the matrix something like
for(int r = 0;r < matrix.length;c++) {	
	    for(int c = 0;c < r.length;r++) {	
		double val = matrix[r][c];
	    }
	}

Open in new window

Oops. Inner loop should be
for(int c = 0;c < r.length;c++) {

Open in new window

But it all depends how you store them.
In math coordinates just a set of two numnes - it is true but in Java you
can represent them as objecvt wit two fields x and y and methods to retrives them
or as a vector with tow elments or in some other way - fromal
program wioill be different