cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Translate the entire conversation x

Using On Error

CarlosRomero
14-Alexandrite

Using On Error

Dear forum,

Does anyone know what the error is and why it doesn't give the result I expect?

Regards,

CarlosRomero

ACCEPTED SOLUTION

Accepted Solutions

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.

Werner_E_2-1708628319060.png

 

So you can also easily create a trimZeroRowsandCols( ) function in one line:

Werner_E_1-1708628265681.png

 

BTW, here is an alternative trimZeroCols( ) function which does not make use of my Is Element( ) function

Werner_E_3-1708628932754.png

 

 

 

View solution in original post

10 REPLIES 10
lvl107
20-Turquoise
(To:CarlosRomero)

  Hello, CarlosRomero

  It seems to be :

1.PNG2.PNG

3.PNG

   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.

Werner_E_2-1708628319060.png

 

So you can also easily create a trimZeroRowsandCols( ) function in one line:

Werner_E_1-1708628265681.png

 

BTW, here is an alternative trimZeroCols( ) function which does not make use of my Is Element( ) function

Werner_E_3-1708628932754.png

 

 

 

CarlosRomero
14-Alexandrite
(To:Werner_E)

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.

lvl107
20-Turquoise
(To:CarlosRomero)

 There is another approach that without trim(  ) and match(  ) built-in function, CarlosRomero :

a.PNG

b.PNG

  Regards.

      Loi.

 

Werner_E
25-Diamond I
(To:lvl107)

Werner_E_0-1708667097468.png

 

lvl107
20-Turquoise
(To:Werner_E)

  You're right, Werner. 🤔 😊

 

 Regards.

ttokoro
21-Topaz I
(To:lvl107)

Prime 9

image.pngimage.pngimage.png

image.pngimage.png

image.pngimage.png

Werner_E
25-Diamond I
(To:ttokoro)

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:

Werner_E_0-1708738285063.png

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

Werner_E_2-1708739458678.png

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  😉

lvl107
20-Turquoise
(To:CarlosRomero)

   Hi, again, CarlosRomero.

   So far, I guess your this question has NOT been solved with both of ORIGIN := 1 and ORIGIN := 0 !!! 🤔

   With :

1.PNG

      Regards.

         Loi.

Announcements

Top Tags