Its easy to delete zero rows or colomn in matlab but I am stuck with this problem with my current c code that I have to remove all zero rows and colomns to make my solver more faster. I couldn’t find any simple way. Could you help me in any convenient way?
Share
For removing only leading and trailing rows and columns
We can implement a matrix n a way that makes these operations fairly efficient.
You allocate a large block to hold the maximal amount of data as if it were a 2D array (
[][]), and do aYou will need to write initialization and cleanup routines. Old c hands will note that we could use the array trick here (or the spiffy new variable length member facility)
Accessing element (i,j) goes something like
This has about twice the complexity of element access from a normal 2D array and can be simplified to a single line at the cost of a little clarity (but your compiler might do that for you).
Removal of rows and columns involves decrementing the appropriate “use value” and also the appropriate “offset” value if you are taking it from the front.
Because the structure is more complicated and requires more bookkeeping than a plain old 2D array you’ll want to wrap all operation on it up in functions.
Old Fortran77 programers may recognize this as a re-implementation of the “passing a contiguous sub-array to a function” idiom.