I have an matrix in this format that I am trying to validate and remove first row:
3 4
0 0 0
0 0 0
0 0 0
0 0 0
Where the first line is and the other lines are the actual data.
Width Height
What is the best way to A remove the first row, and B validate that all rows meet the Width Height Criteria specified? I could do a simple for loop and copy them but I am looking for a more elegant way to do it? Maybe with Linq or one of the Collection Methods?
So far I have:
string[] lines = File.ReadAllLines(fileName);
//first line is width/hight
int length = lines.Length ==0 ;
if(|| (length > 0 && lines[0].Length !=2 ) ){
throw new InvalidDataException("File is not correctly formated:" + fileName);
}
int width = lines[0][0];
int hieght = lines[0][1];
//Check Row count
if(length != height -1){
throw new InvalidDataException("Invalid missing rows in the Matrix definition");
}
//make sure the file is correctly formated with width and height:
if(lines.Any(x=>x.Length != Width)){
//I know this fails because of first line
throw new InvalidDataException("Invalid Width in a row in the Matrix");
}
Any suggestions on a better way to validate input?
Similar:
- matrix formulation Hi everybody, I have polynominal, F = 1+2x+3x^24x^3+5x^4+6x^5+7x^6 that I would luv to put in matrix form that is shown below [7 0 0 0...
- How do I solve this sparse matrix storage problem in C? Hello, I have a sparse matrix that is not symmetric I.E. the sparsity is somewhat random, and I can’t count on all the values being...
- How to efficiently store a matrix with highly-redundant values I have a very large matrix (100M rows by 100M columns) that has a lots of duplicate values right next to each other. For example:...
- [CSS 2.1] [section 9.5 Floats] Empty floated element with a set width but height:0 Hello all, Does an empty floated element with a set width occupy an horizontal space on a line? Testcase: http://www.gtalbot.org/BrowserBugsSection/css21testsuite/floats-107-gt.html According to Ian Hickson, div#zero-height-first-float...
- [CSS 2.1] [section 9.5 Floats] Empty floated element with a set width but height:0 Hello all, Does an empty floated element with a set width occupy an horizontal space on a line? Testcase: http://www.gtalbot.org/BrowserBugsSection/css21testsuite/floats-107-gt.html According to Ian Hickson, div#zero-height-first-float...
[...] Skip first row in a Matrix, and validate width/height. | The … [...]