CAn we define this kind of constructor
-
I want to define a class (which will store a 2D matrix and will do some operations on that). Say I want to define a 2D matirx [1 2 3 ;1 2 3; 3 4 5] and I have a GUI to enter the data, where I enter
matrix(1,2,3;1,2,3;3,4,5)
and it constructs the matrix [1 2 3 ;1 2 3; 3 4 5]. Can someone help me how to acheive this? -
I want to define a class (which will store a 2D matrix and will do some operations on that). Say I want to define a 2D matirx [1 2 3 ;1 2 3; 3 4 5] and I have a GUI to enter the data, where I enter
matrix(1,2,3;1,2,3;3,4,5)
and it constructs the matrix [1 2 3 ;1 2 3; 3 4 5]. Can someone help me how to acheive this?Maybe you can do something like
new Matrix(
new MatrixRow(1, 2, 3),
new MatrixRow(1, 2, 3),
new MatrixRow(3, 4, 5)
);Does that help? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
I want to define a class (which will store a 2D matrix and will do some operations on that). Say I want to define a 2D matirx [1 2 3 ;1 2 3; 3 4 5] and I have a GUI to enter the data, where I enter
matrix(1,2,3;1,2,3;3,4,5)
and it constructs the matrix [1 2 3 ;1 2 3; 3 4 5]. Can someone help me how to acheive this? -
To store a two dimensional array, you use an array of arrays.
int[][] matrix; matrix = new int[3][]; for (int i=0; i<3; i++) matrix[i] = new int[3];
Now you have a 3x3 array that you can store the values in. --- b { font-weight: normal; }But only problem is that i don't know what will be the size of the mastirx before hand. I just gave u an example ,..it could be any n*m matrix.
-
But only problem is that i don't know what will be the size of the mastirx before hand. I just gave u an example ,..it could be any n*m matrix.
-
You can replace the numbers with variables containing any number you want. --- b { font-weight: normal; }
Have you worked in MATLAB? its like nothing is mentioned? you just enter >>[1 2 3,4 5 6;8 9 6] and it creates a matrix. i want some application lik ethat. by looking at the expression user entered you construct the matrix. i know we can do that by defiing a variable. but how to determine th eorder of the matrix (n*m) by looking at the expression. bec as far as i know constructor takes only parameters. trick here is that by looking at the string 1 2 3,4 5 6;8 9 6 your constructor should be able to say that it is a 3*3 matrix and defines the matrix accordingly
-
Have you worked in MATLAB? its like nothing is mentioned? you just enter >>[1 2 3,4 5 6;8 9 6] and it creates a matrix. i want some application lik ethat. by looking at the expression user entered you construct the matrix. i know we can do that by defiing a variable. but how to determine th eorder of the matrix (n*m) by looking at the expression. bec as far as i know constructor takes only parameters. trick here is that by looking at the string 1 2 3,4 5 6;8 9 6 your constructor should be able to say that it is a 3*3 matrix and defines the matrix accordingly
Split the string by semicolon:
string input = "1 2 3;4 5 6;7 8 9"; string[] rows = input.Split(';');
Now you have an array with three records. Create an array of string arrays to store the final result:string[][] matrix = new string[rows.Length][];
Now split each row by space to get an array, and put it in the matrix:for (int i=0; i<rows.Length; i++) matrix[i] = rows[i].Split(' ');
--- b { font-weight: normal; } -
Split the string by semicolon:
string input = "1 2 3;4 5 6;7 8 9"; string[] rows = input.Split(';');
Now you have an array with three records. Create an array of string arrays to store the final result:string[][] matrix = new string[rows.Length][];
Now split each row by space to get an array, and put it in the matrix:for (int i=0; i<rows.Length; i++) matrix[i] = rows[i].Split(' ');
--- b { font-weight: normal; }Thanks..solves my problem. u exactly got into the root of the problem.
-
Thanks..solves my problem. u exactly got into the root of the problem.