|
Post by bobpit on May 24, 2017 8:19:27 GMT
When I do StaticVarGet("myvar"), how can I be sure that I have read a valid static variable, when "myvar" is a matrix?
If the static var is a number, then the code would be:
StaticVarRemove( "myvar"); x1 = 18; // number StaticVarSet( "myvar" , x1); x2 = Nz(StaticVarGet("myvar"));
However, if the static var is a Matrix, the following code does snot work:
StaticVarRemove( "myvar"); x1 = Matrix( 4,5,-5); // matrix StaticVarSet( "myvar" , x1); x2 = Nz(StaticVarGet("myvar"));
So how can I check that x2 is not null and I actually have a static variable in x2?
|
|
fxshrat
Private Group
Posts: 566
Received Likes: 211
|
Post by fxshrat on May 24, 2017 8:54:22 GMT
For example you may use typeof operator for checking for type matrix.
if( typeof( mat ) == "matrix" ){ // do something } else { // else do something else }
And FYI, Nz is not a matrix function. It operates on numbers (-> matrix elements) or arrays.
|
|
|
Post by bobpit on May 24, 2017 9:20:44 GMT
typeof() works! Thank you very much.
Here is sample code:
StaticVarRemove( "myvar"); x1 = Matrix( 400,5,-5); // x1 = 18; // number StaticVarSet( "myvar" , x1); x2 = StaticVarGet("myvar");
"Typeof(x2) : " + typeof( x2); if (typeof( x2)=="matrix") printf("Success !!!\n");
"All variables in memory: " + StaticVarInfo( "myvar", "list" ); " Total static var memory: " + StaticVarInfo( "myvar", "totalmemory"); " Memory (bytes): " + StaticVarInfo( "myvar", "memory" );
|
|