Hi everyone

I'd like to know how I can fill a matrix [n] [m] from a vector of size n * m

Thank you very much every one

Are you using a library that has matrix and vector classes? Are you using arrays? It seems to me, if you're using something pretty simple (such as arrays), moving through each index of the vector and copying the contents of that location in the vector to the matrix would work well.

You'll need to provide some more information for anybody to really understand what you are having trouble with, though.

thank you verry much thats my code

``````String parseText = "    MMKP" + "\n" +
"{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1}" + "\n" +
"Initial" + "\n" +
"propagators: 25" + "\n" +
"branchers:   1" + "\n" +
"Summary" + "\n" +
"runtime:      0.003 (3.000 ms)" + "\n" +
"solutions:    1" + "\n" +
"propagations: 125" + "\n" +
"nodes:        8" + "\n" +
"failures:     1" + "\n" +
"restarts:     0" + "\n" +
"peak depth:   6" + "\n" +
"peak memory:  10 KB" + "\n" +
"Appuyez sur une touche pour continuer...";
// convert String into InputStream
InputStream is = new ByteArrayInputStream(parseText.getBytes());
String line = null;
try {
Vector res4 = new  Vector();
while ((line = br.readLine()) != null) {
String txt = line.trim();
//Ligne de texte qui commence par { et se termine par }
if(txt.startsWith("{" ) && txt.endsWith("}" )) {
//On enleve les accolades (1er et dernier caractere) avec substring
//http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#substring%28int,%20int%29
//On garde les elements espaces par des virgules avec split
//http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split%28java.lang.String%29
String[] split = txt.substring(1, txt.length() - 1).split(",\\s" );
try{
for(String s : split) {
}
}
catch(NumberFormatException e){
e.printStackTrace();
}
}
}
System.out.println("Resultat :" );
for(int i=0;i<res4.size();i++)
System.out.print(res4.get(i)+",");

System.out.println();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
``````

in my appliacation i have to send parametrs from my java code to c++ code , after that i get the answer in the java console so i put it in string then put them in inputstream , i have to get what is between "{"and "}" get the integers and put them in a matrix[n][m] that i need to use it
after that in my code , i hope that you can help me with taht
Thank you very much every one

By matrix, I assume you mean array. With new Java, you should not be using the Vector class; it is deprecated (which means it's old and might not work as well as the new class, ArrayList).

It looks to me like you want to make an two-dimensional array of `int`s. Then, loop through the vector, adding each item to the correct spot in the array. (there's a simple algorithm for this, but, in case this is an assignment, I'll leave that to you).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.