• Status: Solved
• Priority: Medium
• Security: Public
• Views: 393

# 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)

``````for(int i=0; i<Matrix.length; i++){
do some calculation
}
``````
0
ZURINET
• 10
• 4
• 4
1 Solution

Commented:
if(i == 3)

should do it shouldn't it?
0

Commented:
``````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
}
}
``````
0

Commented:
Sorry

if(i == 2)
0

Commented:

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

0

Commented:
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
0

Author Commented:
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)

}
0

Commented:

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]...
}
``````

0

Commented:
``````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]...
}
``````
0

Commented:
By passing a "vector" - do you mean it is array ot it is an ArrayList - how do you hold these
values x and y ?
0

Commented:
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?
0

Author Commented:
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..

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

0

Author Commented:
I am looking for a way to tell the loop to skip some pointer .. or coordinate x,y in the dimention
0

Commented:
``````for(int i=0; i<Matrix.length; i++){
if(Matrix[i].getX() == 1 && Matrix[i].getY() ==0)continue;
//do somthing with matrix[i]...
}
``````
0

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

Thanks
0

Commented:
So if elements of your Matrix are objects which have methods getX() and getY()
returning numbers, then the oabove post should do it.
If they are doble values iit is better to write:

``````for(int i=0; i<Matrix.length; i++){
if(Matrix[i].getX() == 1.0 && Matrix[i].getY() ==0.0)continue;
//do somthing with matrix[i]...
}
``````
0

Commented:
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];
}
}
``````
0

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

Commented:
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
0

## Featured Post

• 10
• 4
• 4
Tackle projects and never again get stuck behind a technical roadblock.