cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP Security Notice: CVE-2026-109618 and CVE-2026-109619

    JMP promptly initiated a review of its products, services, and relevant infrastructure for exposure to CVE-2026-109618 and CVE-2026-109619.

    Our assessment of JMP products has not identified exposure to these vulnerabilities. Where remediation was required within supporting environments, appropriate security updates and controls have been applied and validated.

    We have identified no evidence of successful exploitation or unauthorized access to JMP systems or customer information associated with these vulnerabilities.

    JMP continues to monitor the issue and relevant vendor guidance. No action is required by JMP customers at this time.

  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
mtowle419
Level II

Are there ways to populate a 5x5 matrix with values 101..505 without using loops?

Surely there are ways! 

 

Loop version:

 

ii = 1::5; jj = 1::5;

m = j(5,5);

foreach({i}, ii,
	foreach({j}, jj,
		m[i,j] = i*100 + j
	)
);

m;

#=> [ 101 102 103 104 105, 
	201 202 203 204 205, 
	301 302 303 304 305, 
	401 402 403 404 405, 
	501 502 503 504 505];

Multiple solutions encouraged, if you have them! I'm trying to "get fluent" in matrices.

 

 

3 ACCEPTED SOLUTIONS

Accepted Solutions
Craige_Hales
Super User

Re: Are there ways to populate a 5x5 matrix with values 101..505 without using loops?

x = J( 5, 5, . );
Parallel Assign( {}, x[r, c] = 100 * r + c );
x;
[101 102 103 104 105,
201 202 203 204 205,
301 302 303 304 305,
401 402 403 404 405,
501 502 503 504 505]

or

n = 5;
x = 1 :: n;
y = 100 * x;
Repeat( x, n ) + Repeat( y, n )`;
[101 102 103 104 105,
201 202 203 204 205,
301 302 303 304 305,
401 402 403 404 405,
501 502 503 504 505]

 

 

Craige

View solution in original post

Re: Are there ways to populate a 5x5 matrix with values 101..505 without using loops?

(101::105) |/ (201::205) |/ (301::305) |/ (401::405) |/ (501::505)

View solution in original post

jthi
Super User

Re: Are there ways to populate a 5x5 matrix with values 101..505 without using loops?

Can get slow but you can also use JSL code with J() function

Names Default To Here(1);

n = 5;

i = 1;
m = J(n, n, 
	Ceiling(i / n) * 100 + Mod(i++ - 1, n) + 1
);

Write();

 

-Jarmo

View solution in original post

4 REPLIES 4
mtowle419
Level II

Re: Are there ways to populate a 5x5 matrix with values 101..505 without using loops?

Got one, finally. It ain't pretty though

 

a = shape(mod(0::24, 5) + 1, 5);

#=> [1 2 3 4 5,
1 2 3 4 5,
1 2 3 4 5,
1 2 3 4 5,
1 2 3 4 5]

b = shape(floor(index(10, 58, 2) / 10), 5) * 100;

#=> [100 100 100 100 100,
200 200 200 200 200,
300 300 300 300 300,
400 400 400 400 400,
500 500 500 500 500]

a+b;

#=> [101 102 103 104 105,
201 202 203 204 205,
301 302 303 304 305,
401 402 403 404 405,
501 502 503 504 505]

 

jthi
Super User

Re: Are there ways to populate a 5x5 matrix with values 101..505 without using loops?

Can get slow but you can also use JSL code with J() function

Names Default To Here(1);

n = 5;

i = 1;
m = J(n, n, 
	Ceiling(i / n) * 100 + Mod(i++ - 1, n) + 1
);

Write();

 

-Jarmo
Craige_Hales
Super User

Re: Are there ways to populate a 5x5 matrix with values 101..505 without using loops?

x = J( 5, 5, . );
Parallel Assign( {}, x[r, c] = 100 * r + c );
x;
[101 102 103 104 105,
201 202 203 204 205,
301 302 303 304 305,
401 402 403 404 405,
501 502 503 504 505]

or

n = 5;
x = 1 :: n;
y = 100 * x;
Repeat( x, n ) + Repeat( y, n )`;
[101 102 103 104 105,
201 202 203 204 205,
301 302 303 304 305,
401 402 403 404 405,
501 502 503 504 505]

 

 

Craige

Re: Are there ways to populate a 5x5 matrix with values 101..505 without using loops?

(101::105) |/ (201::205) |/ (301::305) |/ (401::405) |/ (501::505)

Recommended Articles