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

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

0
ZURINET
Asked:
ZURINET
  • 10
  • 4
  • 4
1 Solution
 
CEHJCommented:
if(i == 3)

should do it shouldn't it?
0
 
for_yanCommented:
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

0
 
CEHJCommented:
Sorry

if(i == 2)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
for_yanCommented:

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

0
 
for_yanCommented:
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
 
ZURINETAuthor 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
 
for_yanCommented:

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



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

0
 
for_yanCommented:
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
 
for_yanCommented:
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
 
ZURINETAuthor 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..
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..

0
 
ZURINETAuthor Commented:
I am looking for a way to tell the loop to skip some pointer .. or coordinate x,y in the dimention
0
 
for_yanCommented:
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

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

Thanks
0
 
for_yanCommented:
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]...
}

Open in new window

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

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

Open in new window

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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