Skip to main content
1-Visitor
Sep 12, 2014 5:11 PM UTC
Solved

test if a variable is a matrix

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]))

1-Visitor
Sep 12, 2014 5:56 PM UTC

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.

4 replies

23-Emerald I
Sep 12, 2014 5:28 PM UTC

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

Translate
1-Visitor
Sep 12, 2014 5:37 PM UTC

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

Translate
1-Visitor
Sep 12, 2014 5:39 PM UTC

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

Translate
ptc-38363061-VisitorAuthorAnswer
1-Visitor
Sep 12, 2014 5:56 PM UTC

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.

Translate