Dear forum,
Does anyone know what the error is and why it doesn't give the result I expect?
Regards,
CarlosRomero
Solved! Go to Solution.
I don't understand why you expected a different result than the one you got!
The function does exactly what its name suggests - it deletes all COLUMNS in a matrix which consist of all zeros.
The function does not claim to deal with the rows, so rows with all-zero values remain intact.
To remove the all-zero rows as well you need a function trimZeroRows( ). But you don't have to write that function, simply use trimZeroCols on the transposed matrix and then transpose the result.
So you can also easily create a trimZeroRowsandCols( ) function in one line:
BTW, here is an alternative trimZeroCols( ) function which does not make use of my Is Element( ) function
Hello, CarlosRomero
It seems to be :
Best Regards.
Loi.
I don't understand why you expected a different result than the one you got!
The function does exactly what its name suggests - it deletes all COLUMNS in a matrix which consist of all zeros.
The function does not claim to deal with the rows, so rows with all-zero values remain intact.
To remove the all-zero rows as well you need a function trimZeroRows( ). But you don't have to write that function, simply use trimZeroCols on the transposed matrix and then transpose the result.
So you can also easily create a trimZeroRowsandCols( ) function in one line:
BTW, here is an alternative trimZeroCols( ) function which does not make use of my Is Element( ) function
Thanks Loi and Werner.
A good solution Loi.
Werner, thanks for pointing out that to delete the rows it was only necessary to use the transposed trimZeroCols.
I attach your alternative function that does not use IsElement but returns an error?
Regards,
CarlosRomero
Uhh, that one was a bit tricky 😉
Right click at the bar after the sum symbol. The menu which pops up gives you (amongst others) the choice between "Absolute Value" and "Square Matrix Determinant". Check "Absolute Value" and the function works OK.
There is another approach that without trim( ) and match( ) built-in function, CarlosRomero :
Regards.
Loi.
You're right, Werner. 🤔 😊
Regards.
Prime 9
As I understood the goal is just to eliminate columns and rows which consist of ALL zeros!
You can't remove ALL zeros in a matrix and expect it to remain rectangular. At worst you could even end up adding zeros trying to do so.
Your tZ function might yield funny results if the number of non-zero values per row is not all the same. As you, as usual, don't post your sheet you'll have to test it yourself.
BTW, you don't show which of the posted "trimZeroCols( )" functions you are using but I guess its the one using the trim() function. This function is known to be a numeric only function and so a symbolic evaluation must fail.
It was not asked for a symbolic evaluation but if you really need it, you simply can use the initially posted version:
I expect your tZ function to yield a 4x3 matrix with three zeros as well with this matrix, but those zeros would be positioned at the end of their rows and so the column order of the non-zero numbers is changed. Not sure if an application would make use of this behaviour.
Of course there are many ways to write a trimZeroCols() function which also can be evaluated symbolically. Here is an example which does not use any built-in functions
And there sure are many other ways to accomplish the same.
Personally I prefer a modular approach over a "do it all" - start with a function which removes the zero-columns and use this very same function to also remove the zero-rows.
BTW, the sheet posted by Carlos is using ORIGIN:=1 😉
Hi, again, CarlosRomero.
So far, I guess your this question has NOT been solved with both of ORIGIN := 1 and ORIGIN := 0 !!! 🤔
With :
Regards.
Loi.