cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lala
Level VIII

Can a number in an array be replaced by a variable?

For example, in the drawing of JSL the following values

Color Levels([-7.28 -1.99 3.3 8.59 13.88]);

How can I write code in this form?

x1=-7.28;
x2=13.88;
Color Levels([x1 -1.99 3.3 8.59 x2]);

Thanks!

2 ACCEPTED SOLUTIONS

Accepted Solutions
ErraticAttack
Level VI

Re: Can a number in an array be replaced by a variable?

Matrices can be a little tricky, but here is what I do in that situation:

 

x1 = -7.28;
x2 = 13.88;
Color Levels( (x1 |/ [-1.99 3.3 8.59]` |/ x2)` );

This uses the matrix join operator |/ then a few transposes to make it have the correct dimensions

Jordan

View solution in original post

julian
Community Manager Community Manager

Re: Can a number in an array be replaced by a variable?

If you construct your matrix using the Matrix() function you can call in variables as arguments directly. For example:

x1=-7.28;
x2=13.88;
mat = matrix({x1,-1.99, 3.3, 8.59, x2})`
//notice the need to transpose; the syntax is easier to construct this way

Here's a more complete building the entire matrix dynamically: 

Names Default To Here( 1 );

x1=100000; x2=1000000; x3=10000000;

dt = Open( "$SAMPLE_DATA/PopAgeGroup.jmp" );
obj = dt << Bubble Plot(
	X( :"Portion 0-19"n ),
	Y( :"Portion60+"n ),
	Sizes( :Pop ),
	ID( :Country ),
	Coloring( :Pop )
);
obj << Color Levels( matrix({x1,x2,x3})` );

I hope this helps!

@julian 

View solution in original post

3 REPLIES 3
lala
Level VIII

回复: Can a number in an array be replaced by a variable?

OK

2022-12-10_15-58-59.png

ErraticAttack
Level VI

Re: Can a number in an array be replaced by a variable?

Matrices can be a little tricky, but here is what I do in that situation:

 

x1 = -7.28;
x2 = 13.88;
Color Levels( (x1 |/ [-1.99 3.3 8.59]` |/ x2)` );

This uses the matrix join operator |/ then a few transposes to make it have the correct dimensions

Jordan
julian
Community Manager Community Manager

Re: Can a number in an array be replaced by a variable?

If you construct your matrix using the Matrix() function you can call in variables as arguments directly. For example:

x1=-7.28;
x2=13.88;
mat = matrix({x1,-1.99, 3.3, 8.59, x2})`
//notice the need to transpose; the syntax is easier to construct this way

Here's a more complete building the entire matrix dynamically: 

Names Default To Here( 1 );

x1=100000; x2=1000000; x3=10000000;

dt = Open( "$SAMPLE_DATA/PopAgeGroup.jmp" );
obj = dt << Bubble Plot(
	X( :"Portion 0-19"n ),
	Y( :"Portion60+"n ),
	Sizes( :Pop ),
	ID( :Country ),
	Coloring( :Pop )
);
obj << Color Levels( matrix({x1,x2,x3})` );

I hope this helps!

@julian