Skip to main content
1-Visitor
September 12, 2014
Solved

test if a variable is a matrix

  • September 12, 2014
  • 2 replies
  • 1771 views

Is there a way to test if a variable is a matrix in Prime 2.0?

I'm writting a function that uses the function vertflip. I want my function to accept a scaler or matrix, but vertflip only accepts matricies. So I'm looking to do something like...

vertflip(if(ismatrix(M), M, [M]))

Best answer by ptc-3836306

Got it. The "rows" function accepts a scalar or matrix and returns a zero if given a scalar. I just have to check if rows(x) = zero, and then return the function without the reverse operation.

2 replies

23-Emerald I
September 12, 2014

Can you use "reverse" and do it for all columns?

1-Visitor
September 12, 2014

I was unaware of "reverse" but it won't accept a scalar either.

1-Visitor
September 12, 2014

Ooo. Reverse accepts units. Much better than vertflip for my purposes. Thanks.

ptc-38363061-VisitorAuthorAnswer
1-Visitor
September 12, 2014

Got it. The "rows" function accepts a scalar or matrix and returns a zero if given a scalar. I just have to check if rows(x) = zero, and then return the function without the reverse operation.