cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
MFVIT
Level IV

use of parameters in 'select where' and 'name selection in column'

Hello,

I need to take a data table made up of two columns, X and Y, select several rows of the data table and name the selection. This corresponds to select twenty rectangles in the x-y cartesian space and name them with a number (from 1 to 20) (I am working with an image). 

I wrote a script but it does not work. I think I need to solve two problems: 1) how can I use a parameter, see X1, X2, .., in the argument of 'select where'? 2) how can I use a parameter, see n_patch, in the argument of 'name selection in column'? 

Many thanks.

 

Here is the script:

 

 

dt = Current Data Table();
X0 = 2332;
Y0 = 558;

n_patch = 0;
delta_x = 100;
delta_y = 100;
dist_y = 488;
dist_x = 656;
L_x = 500;
L_y = 500;
For( n_x = 1, n_x <= 4, n_x++,
	For( n_y = 1, n_y <= 5, n_y++,
		Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
		Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
		n_patch = n_patch + 1;
		X1 = Xc - delta_x;
		X2 = Xc + delta_x;
		Y1 = Yc - delta_y;
		Y2 = Yc + delta_y;
		dt << Row Selection(
			Select where( (:X >= X1 & :X <= X2) & (Y >= Y1 & Y <= Y2) )
		);

		dt << Name Selection in Column(
			Column Name( "Patch#" ),
			Selected( ("n_patch") ),
			Unselected( "" )
		);
	)
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: use of parameters in 'select where' and 'name selection in column'

You might be using a bit older version of JMP so I'm not sure if these will work for you (not using Row Selection or Name Selection in column).

 

You can get rows of interest with << get rows where and then set values with column()[rows]

dt << New Column("Patch#", Character);
For( n_x = 1, n_x <= 4, n_x++,
	For( n_y = 1, n_y <= 5, n_y++,
		Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
		Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
		n_patch = n_patch + 1;
		X1 = Xc - delta_x;
		X2 = Xc + delta_x;
		Y1 = Yc - delta_y;
		Y2 = Yc + delta_y;
		wantedRows = dt << get rows where(:X >= X1 & :X <= X2 & :Y >= Y1 & :Y <= Y2);
		Column(dt, "Patch#")[wantedRows] = char(n_patch);
	)
);
-Jarmo

View solution in original post

4 REPLIES 4
ih
Super User (Alumni) ih
Super User (Alumni)

Re: use of parameters in 'select where' and 'name selection in column'

Hi @MFVIT,

 

You need to make sure the values of X1 and Y1 are evaluated in your script, rather than looking for something in the data table itself.  This problem is illustrated in Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute. You can ensure this happens by using Eval( Eval Expr( ) ). Here is an example using your code with an example data table.

 

Names default to here(1);

dt = New Table( "Example Data",
	Add Rows( 10000 ),
	New Column( "X", Numeric, "Continuous", Format( "Best", 12 ),
		Formula( Random Uniform( 0, 10000 ) ) ),
	New Column( "Y", Numeric, "Continuous", Format( "Best", 12 ),
		Formula( Random Uniform( 0, 10000 ) ) )
);

X0 = 2332;
Y0 = 558;

n_patch = 0;
delta_x = 100;
delta_y = 100;
dist_y = 488;
dist_x = 656;
L_x = 500;
L_y = 500;

For( n_x = 1, n_x <= 4, n_x++,
	For( n_y = 1, n_y <= 5, n_y++,
		Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
		Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
		n_patch = n_patch + 1;
		X1 = Xc - delta_x;
		X2 = Xc + delta_x;
		Y1 = Yc - delta_y;
		Y2 = Yc + delta_y;
		Eval( Eval Expr(
			dt << Row Selection(
				Select where( (:X >= Expr( X1 ) & :X <= Expr( X2 )) & (:Y >= Expr( Y1 ) & :Y <= Expr( Y2 ) ) )
			);
		) );
		dt << run formulas;
		dt << Name Selection in Column(
			Column Name( "Patch#" || char( n_patch ) ),
			Selected( "n_patch = " || char( n_patch ) ),
			Unselected( "" )
		);
	)
);
MFVIT
Level IV

Re: use of parameters in 'select where' and 'name selection in column'

Hello, thank your very much for your prompt reply.

 

Your code is very useful to me, I think I am on the right way. However, there is still something that does not work.

I tried to run your code and I saw that it adds many column with names 'Patch#1', 'Patch#2', etc. so I changed the line 

Column Name( "Patch#" || char( n_patch ) )

with 

Column Name( "Patch#")

because I want just one column with the name Patch#.

 

But the code does not select what I expect to be selected. It selects only patch5, 10, 15 and 20 and not the other patches and furthermore the selected rows do not correspond to patches..

So, I am not sure the selection command is working correctly.

Many thanks for any help.

Marcello.

 

 

jthi
Super User

Re: use of parameters in 'select where' and 'name selection in column'

You might be using a bit older version of JMP so I'm not sure if these will work for you (not using Row Selection or Name Selection in column).

 

You can get rows of interest with << get rows where and then set values with column()[rows]

dt << New Column("Patch#", Character);
For( n_x = 1, n_x <= 4, n_x++,
	For( n_y = 1, n_y <= 5, n_y++,
		Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
		Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
		n_patch = n_patch + 1;
		X1 = Xc - delta_x;
		X2 = Xc + delta_x;
		Y1 = Yc - delta_y;
		Y2 = Yc + delta_y;
		wantedRows = dt << get rows where(:X >= X1 & :X <= X2 & :Y >= Y1 & :Y <= Y2);
		Column(dt, "Patch#")[wantedRows] = char(n_patch);
	)
);
-Jarmo
MFVIT
Level IV

Re: use of parameters in 'select where' and 'name selection in column'

Thank you very much. The code is very compact and worked.