- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How to fill Matrix using a nested loop
I am trying to extract a specific set of numeric data from a file (which contains both text and numbers) and put it into a separate table which is easier to analyze in JMP. I want the script to work for any number of columns or rows where the data meeting specific criteria might be. What I have come up with is below:
Rowlist = [];
For( i = 1, i <= N Rows( Dtraw ), i++,
If( i == 1,
If( Num( Column( Dtraw, 2 )[i] ) > 0 & Num( Column( Dtraw, 2 )[i] ) < 1000,
Rowlist = Matrix( i )
),
If( Num( Column( Dtraw, 2 )[i] ) > 0 & Num( Column( Dtraw, 2 )[i] ) < 1000,
Rowlist = V Concat( Rowlist, Matrix( i ) )
)
)
);
show(Rowlist);
cols= dtraw<<get column names();
MainData=J(nitems(rowlist),nitems(cols)-1);
For( i = 1, i <= N Items( rowlist ), i++,
For( k = 2, k <= N items ( cols ), i++,
MainData[i,k] = Num( Column( dtraw, k )[rowlist[i]] );
)
);
show(MainData);
Rowlist is the matrix of rows that meet the criteria I need (that is, they are numbers and not text). I want to use this list and "<<get column names" to define the regions of my raw data file where the data I need resides. I want to extract that specific data into a different table. The first For loop for Rowlist works just fine, but the nested for loop does not do what I want and I can't figue out why. Can anyone help me with this?
-Thanks
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to fill Matrix using a nested loop
You have a couple of typing errors.
1. Your second For Loop
For( k = 2, k <= N Items( cols ), i++,
you are incrementing "i", not "k". It should be
For( k = 2, k <= N Items( cols ), k++,
Secondly, you need to subtract 1 from k when referencing your MainData matrix, otherwise you will go beyond the range, since it is 1 less than the number of columns.
MainData[i, k - 1] = Num( Column( dtraw, k - 1 )[rowlist[i]] )
The whole section should be:
For( i = 1, i <= N Rows( rowlist ), i++,
For( k = 2, k <= N Items( cols ), k++,
MainData[i, k - 1] = Num( Column( dtraw, k - 1 )[rowlist[i]] )
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to fill Matrix using a nested loop
Of course, the code looks 'roughly right'.
What error do you actually see, please? Can you upload a part of 'dtraw'?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to fill Matrix using a nested loop
I get the error message below:
invalid subscript (must be number or list of numbers){1271} in access or evaluation of 'Subscript' , rowlist[/*###*/i]
In the following script, error marked by /*###*/
Show( Rowlist );
cols = dtraw << get column names();
MainData = J( N Items( rowlist ), N Items( cols ) - 1 );
For( i = 1, i <= N Items( rowlist ), i++,
For( k = 2, k <= N Items( cols ), i++,
MainData[i, k] = Num( Column( dtraw, k )[rowlist[/*###*/i]] )
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to fill Matrix using a nested loop
You have a couple of typing errors.
1. Your second For Loop
For( k = 2, k <= N Items( cols ), i++,
you are incrementing "i", not "k". It should be
For( k = 2, k <= N Items( cols ), k++,
Secondly, you need to subtract 1 from k when referencing your MainData matrix, otherwise you will go beyond the range, since it is 1 less than the number of columns.
MainData[i, k - 1] = Num( Column( dtraw, k - 1 )[rowlist[i]] )
The whole section should be:
For( i = 1, i <= N Rows( rowlist ), i++,
For( k = 2, k <= N Items( cols ), k++,
MainData[i, k - 1] = Num( Column( dtraw, k - 1 )[rowlist[i]] )
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to fill Matrix using a nested loop
Thank you this works perfectly!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to fill Matrix using a nested loop
Below is a generic example of the data (showing the format):
Date/Time: | 11/29/2017 20:11 | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | Title | Title | Title | Title | Title | Title | Title | Title | Title | Title | Title |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | |
3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | |
4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | |
5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | |
6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | |
7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | |
8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | |
9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | |
10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | |
11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 | |
12 | 12 | 12 | 12 | 12 | 12 | 12 | 12 | 12 | 12 | 12 | |
13 | 13 | 13 | 13 | 13 | 13 | 13 | 13 | 13 | 13 | 13 | |
14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | |
15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | |
16 | 16 | 16 | 16 | 16 | 16 | 16 | 16 | 16 | 16 | 16 | |
17 | 17 | 17 | 17 | 17 | 17 | 17 | 17 | 17 | 17 | 17 | |
18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | |
19 | 19 | 19 | 19 | 19 | 19 | 19 | 19 | 19 | 19 | 19 | |
20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | |
21 | 21 | 21 | 21 | 21 | 21 | 21 | 21 | 21 | 21 | 21 | |
22 | 22 | 22 | 22 | 22 | 22 | 22 | 22 | 22 | 22 | 22 | |
23 | 23 | 23 | 23 | 23 | 23 | 23 | 23 | 23 | 23 | 23 | |
24 | 24 | 24 | 24 | 24 | 24 | 24 | 24 | 24 | 24 | 24 | |
25 | 25 | 25 | 25 | 25 | 25 | 25 | 25 | 25 | 25 | 25 | |
26 | 26 | 26 | 26 | 26 | 26 | 26 | 26 | 26 | 26 | 26 | |
27 | 27 | 27 | 27 | 27 | 27 | 27 | 27 | 27 | 27 | 27 | |
28 | 28 | 28 | 28 | 28 | 28 | 28 | 28 | 28 | 28 | 28 | |
29 | 29 | 29 | 29 | 29 | 29 | 29 | 29 | 29 | 29 | 29 | |
30 | 30 | 30 | 30 | 30 | 30 | 30 | 30 | 30 | 30 | 30 | |
31 | 31 | 31 | 31 | 31 | 31 | 31 | 31 | 31 | 31 | 31 | |
32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | |
33 | 33 | 33 | 33 | 33 | 33 | 33 | 33 | 33 | 33 | 33 | |
34 | 34 | 34 | 34 | 34 | 34 | 34 | 34 | 34 | 34 | 34 | |
35 | 35 | 35 | 35 | 35 | 35 | 35 | 35 | 35 | 35 | 35 | |
36 | 36 | 36 | 36 | 36 | 36 | 36 | 36 | 36 | 36 | 36 | |
37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | |
38 | 38 | 38 | 38 | 38 | 38 | 38 | 38 | 38 | 38 | 38 | |
39 | 39 | 39 | 39 | 39 | 39 | 39 | 39 | 39 | 39 | 39 | |
40 | 40 | 40 | 40 | 40 | 40 | 40 | 40 | 40 | 40 | 40 | |
41 | 41 | 41 | 41 | 41 | 41 | 41 | 41 | 41 | 41 | 41 | |
42 | 42 | 42 | 42 | 42 | 42 | 42 | 42 | 42 | 42 | 42 | |
43 | 43 | 43 | 43 | 43 | 43 | 43 | 43 | 43 | 43 | 43 | |
44 | 44 | 44 | 44 | 44 | 44 | 44 | 44 | 44 | 44 | 44 | |
45 | 45 | 45 | 45 | 45 | 45 | 45 | 45 | 45 | 45 | 45 | |
46 | 46 | 46 | 46 | 46 | 46 | 46 | 46 | 46 | 46 | 46 | |
47 | 47 | 47 | 47 | 47 | 47 | 47 | 47 | 47 | 47 | 47 | |
48 | 48 | 48 | 48 | 48 | 48 | 48 | 48 | 48 | 48 | 48 | |
49 | 49 | 49 | 49 | 49 | 49 | 49 | 49 | 49 | 49 | 49 | |
50 | 50 | 50 | 50 | 50 | 50 | 50 | 50 | 50 | 50 | 50 | |
51 | 51 | 51 | 51 | 51 | 51 | 51 | 51 | 51 | 51 | 51 | |
52 | 52 | 52 | 52 | 52 | 52 | 52 | 52 | 52 | 52 | 52 | |
53 | 53 | 53 | 53 | 53 | 53 | 53 | 53 | 53 | 53 | 53 | |
54 | 54 | 54 | 54 | 54 | 54 | 54 | 54 | 54 | 54 | 54 | |
55 | 55 | 55 | 55 | 55 | 55 | 55 | 55 | 55 | 55 | 55 | |
56 | 56 | 56 | 56 | 56 | 56 | 56 | 56 | 56 | 56 | 56 | |
57 | 57 | 57 | 57 | 57 | 57 | 57 | 57 | 57 | 57 | 57 | |
58 | 58 | 58 | 58 | 58 | 58 | 58 | 58 | 58 | 58 | 58 | |
59 | 59 | 59 | 59 | 59 | 59 | 59 | 59 | 59 | 59 | 59 | |
60 | 60 | 60 | 60 | 60 | 60 | 60 | 60 | 60 | 60 | 60 | |
61 | 61 | 61 | 61 | 61 | 61 | 61 | 61 | 61 | 61 | 61 | |
62 | 62 | 62 | 62 | 62 | 62 | 62 | 62 | 62 | 62 | 62 | |
63 | 63 | 63 | 63 | 63 | 63 | 63 | 63 | 63 | 63 | 63 | |
64 | 64 | 64 | 64 | 64 | 64 | 64 | 64 | 64 | 64 | 64 | |
65 | 65 | 65 | 65 | 65 | 65 | 65 | 65 | 65 | 65 | 65 | |
66 | 66 | 66 | 66 | 66 | 66 | 66 | 66 | 66 | 66 | 66 | |
67 | 67 | 67 | 67 | 67 | 67 | 67 | 67 | 67 | 67 | 67 | |
68 | 68 | 68 | 68 | 68 | 68 | 68 | 68 | 68 | 68 | 68 | |
69 | 69 | 69 | 69 | 69 | 69 | 69 | 69 | 69 | 69 | 69 | |
70 | 70 | 70 | 70 | 70 | 70 | 70 | 70 | 70 | 70 | 70 | |
71 | 71 | 71 | 71 | 71 | 71 | 71 | 71 | 71 | 71 | 71 | |
72 | 72 | 72 | 72 | 72 | 72 | 72 | 72 | 72 | 72 | 72 | |
73 | 73 | 73 | 73 | 73 | 73 | 73 | 73 | 73 | 73 | 73 | |
Value label | 74 | 74 | 74 | 74 | 74 | 74 | 74 | 74 | |||
Value label | 75 | 75 | 75 | 75 | 75 | 75 | 75 | 75 | |||
Value label | 76 | 76 | 76 | 76 | 76 | 76 | 76 | 76 | |||
Value label | 77 | 77 | 77 | 77 | 77 | 77 | 77 | 77 | |||
Value label | 78 | 78 | 78 | 78 | 78 | 78 | 78 | 78 | |||
Value label | 79 | 79 | 79 | 79 | 79 | 79 | 79 | 79 | |||
Value label | 80 | 80 | 80 | 80 | 80 | 80 | 80 | 80 | |||
Value label | 81 | 81 | 81 | 81 | 81 | 81 | 81 | 81 | |||
Date/Time: | 11/29/2017 20:11 | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | TEXT | ||||||||||
Title | Title | Title | Title | Title | Title | Title | Title | Title | Title | Title | Title |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | |
3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | |
4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 | |
5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | |
6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | |
7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | 7 | |
8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | |
9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | |
10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | 10 | |
11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 | 11 | |
12 | 12 | 12 | 12 | 12 | 12 | 12 | 12 | 12 | 12 | 12 | |
13 | 13 | 13 | 13 | 13 | 13 | 13 | 13 | 13 | 13 | 13 | |
14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | 14 | |
15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | 15 | |
16 | 16 | 16 | 16 | 16 | 16 | 16 | 16 | 16 | 16 | 16 | |
17 | 17 | 17 | 17 | 17 | 17 | 17 | 17 | 17 | 17 | 17 | |
18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | 18 | |
19 | 19 | 19 | 19 | 19 | 19 | 19 | 19 | 19 | 19 | 19 | |
20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | 20 | |
21 | 21 | 21 | 21 | 21 | 21 | 21 | 21 | 21 | 21 | 21 | |
22 | 22 | 22 | 22 | 22 | 22 | 22 | 22 | 22 | 22 | 22 | |
23 | 23 | 23 | 23 | 23 | 23 | 23 | 23 | 23 | 23 | 23 | |
24 | 24 | 24 | 24 | 24 | 24 | 24 | 24 | 24 | 24 | 24 | |
25 | 25 | 25 | 25 | 25 | 25 | 25 | 25 | 25 | 25 | 25 | |
26 | 26 | 26 | 26 | 26 | 26 | 26 | 26 | 26 | 26 | 26 | |
27 | 27 | 27 | 27 | 27 | 27 | 27 | 27 | 27 | 27 | 27 | |
28 | 28 | 28 | 28 | 28 | 28 | 28 | 28 | 28 | 28 | 28 | |
29 | 29 | 29 | 29 | 29 | 29 | 29 | 29 | 29 | 29 | 29 | |
30 | 30 | 30 | 30 | 30 | 30 | 30 | 30 | 30 | 30 | 30 | |
31 | 31 | 31 | 31 | 31 | 31 | 31 | 31 | 31 | 31 | 31 | |
32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | |
33 | 33 | 33 | 33 | 33 | 33 | 33 | 33 | 33 | 33 | 33 | |
34 | 34 | 34 | 34 | 34 | 34 | 34 | 34 | 34 | 34 | 34 | |
35 | 35 | 35 | 35 | 35 | 35 | 35 | 35 | 35 | 35 | 35 | |
36 | 36 | 36 | 36 | 36 | 36 | 36 | 36 | 36 | 36 | 36 | |
37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | 37 | |
38 | 38 | 38 | 38 | 38 | 38 | 38 | 38 | 38 | 38 | 38 | |
39 | 39 | 39 | 39 | 39 | 39 | 39 | 39 | 39 | 39 | 39 | |
40 | 40 | 40 | 40 | 40 | 40 | 40 | 40 | 40 | 40 | 40 | |
41 | 41 | 41 | 41 | 41 | 41 | 41 | 41 | 41 | 41 | 41 | |
42 | 42 | 42 | 42 | 42 | 42 | 42 | 42 | 42 | 42 | 42 | |
43 | 43 | 43 | 43 | 43 | 43 | 43 | 43 | 43 | 43 | 43 | |
44 | 44 | 44 | 44 | 44 | 44 | 44 | 44 | 44 | 44 | 44 | |
45 | 45 | 45 | 45 | 45 | 45 | 45 | 45 | 45 | 45 | 45 | |
46 | 46 | 46 | 46 | 46 | 46 | 46 | 46 | 46 | 46 | 46 | |
47 | 47 | 47 | 47 | 47 | 47 | 47 | 47 | 47 | 47 | 47 | |
48 | 48 | 48 | 48 | 48 | 48 | 48 | 48 | 48 | 48 | 48 | |
49 | 49 | 49 | 49 | 49 | 49 | 49 | 49 | 49 | 49 | 49 | |
50 | 50 | 50 | 50 | 50 | 50 | 50 | 50 | 50 | 50 | 50 | |
51 | 51 | 51 | 51 | 51 | 51 | 51 | 51 | 51 | 51 | 51 | |
52 | 52 | 52 | 52 | 52 | 52 | 52 | 52 | 52 | 52 | 52 | |
53 | 53 | 53 | 53 | 53 | 53 | 53 | 53 | 53 | 53 | 53 | |
54 | 54 | 54 | 54 | 54 | 54 | 54 | 54 | 54 | 54 | 54 | |
55 | 55 | 55 | 55 | 55 | 55 | 55 | 55 | 55 | 55 | 55 | |
56 | 56 | 56 | 56 | 56 | 56 | 56 | 56 | 56 | 56 | 56 | |
57 | 57 | 57 | 57 | 57 | 57 | 57 | 57 | 57 | 57 | 57 | |
58 | 58 | 58 | 58 | 58 | 58 | 58 | 58 | 58 | 58 | 58 | |
59 | 59 | 59 | 59 | 59 | 59 | 59 | 59 | 59 | 59 | 59 | |
60 | 60 | 60 | 60 | 60 | 60 | 60 | 60 | 60 | 60 | 60 | |
61 | 61 | 61 | 61 | 61 | 61 | 61 | 61 | 61 | 61 | 61 | |
62 | 62 | 62 | 62 | 62 | 62 | 62 | 62 | 62 | 62 | 62 | |
63 | 63 | 63 | 63 | 63 | 63 | 63 | 63 | 63 | 63 | 63 | |
64 | 64 | 64 | 64 | 64 | 64 | 64 | 64 | 64 | 64 | 64 | |
65 | 65 | 65 | 65 | 65 | 65 | 65 | 65 | 65 | 65 | 65 | |
66 | 66 | 66 | 66 | 66 | 66 | 66 | 66 | 66 | 66 | 66 | |
67 | 67 | 67 | 67 | 67 | 67 | 67 | 67 | 67 | 67 | 67 | |
68 | 68 | 68 | 68 | 68 | 68 | 68 | 68 | 68 | 68 | 68 | |
69 | 69 | 69 | 69 | 69 | 69 | 69 | 69 | 69 | 69 | 69 | |
70 | 70 | 70 | 70 | 70 | 70 | 70 | 70 | 70 | 70 | 70 | |
71 | 71 | 71 | 71 | 71 | 71 | 71 | 71 | 71 | 71 | 71 | |
72 | 72 | 72 | 72 | 72 | 72 | 72 | 72 | 72 | 72 | 72 | |
73 | 73 | 73 | 73 | 73 | 73 | 73 | 73 | 73 | 73 | 73 | |
Value label | 74 | 74 | 74 | 74 | 74 | 74 | 74 | 74 | |||
Value label | 75 | 75 | 75 | 75 | 75 | 75 | 75 | 75 | |||
Value label | 76 | 76 | 76 | 76 | 76 | 76 | 76 | 76 | |||
Value label | 77 | 77 | 77 | 77 | 77 | 77 | 77 | 77 | |||
Value label | 78 | 78 | 78 | 78 | 78 | 78 | 78 | 78 | |||
Value label | 79 | 79 | 79 | 79 | 79 | 79 | 79 | 79 | |||
Value label | 80 | 80 | 80 | 80 | 80 | 80 | 80 | 80 | |||
Value label | 81 | 81 | 81 | 81 | 81 | 81 | 81 | 81 |