Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Using Match on a matrix without loop

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 5, 2018 7:17 PM
(2279 views)

All,

Is it possible to use match on matrices ? I dont see from the documentation that this is possible, but has anyone tried this before ? Essentially, here is an example of what I would like to acheieve without a loop. Wish there was more documentation and blog posts for vectorizing matrix operations in JSL.

```
A = [0.1,0.2,0.3,0.4];
TestMat = [1,2,3,4,4,2,3,1,3,2,4,1];
TestMat1 = J(N Rows(TestMat),1,0);
for(i = 1, i <= N Rows(TestMat), i++,
TestMat1[i,1] = Match(TestMat[i],1,A[1],2,A[2],3,A[3],4,A[4]);
);
Show(TestMat1);
```

Best

Uday

Uday

- Tags:
- Vectorization

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Use TestMat as the Subscript for A and assign it to TestMat1:

```
A = [0.1, 0.2, 0.3, 0.4];
TestMat = [1, 2, 3, 4, 4, 2, 3, 1, 3, 2, 4, 1];
TestMat1 = A[TestMat];
Show(TestMat1);
/*:
TestMat1 = [0.1, 0.2, 0.3, 0.4, 0.4, 0.2, 0.3, 0.1, 0.3, 0.2, 0.4, 0.1];
```

-Jeff

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Use TestMat as the Subscript for A and assign it to TestMat1:

```
A = [0.1, 0.2, 0.3, 0.4];
TestMat = [1, 2, 3, 4, 4, 2, 3, 1, 3, 2, 4, 1];
TestMat1 = A[TestMat];
Show(TestMat1);
/*:
TestMat1 = [0.1, 0.2, 0.3, 0.4, 0.4, 0.2, 0.3, 0.1, 0.3, 0.2, 0.4, 0.1];
```

-Jeff

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Using Match on a matrix without loop

Best

Uday

Uday

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Using Match on a matrix without loop

Thanks Jeff. That worked.

Would request for documentation to be added on vectorizing operations with examples (request/ suggestion) as I search more and more for vectorization in JMP, I realise there are not sufficient blogs/documentation which helps guide users on the topic.

Best

Uday

Uday

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Using Match on a matrix without loop

Scripting Guide, Chapter 7 "Data Structures" Sections: Lists and Matrices have examples. Specifically, the Matrices subsections: "Subscripts" and "Indexing into a Matrix or List with Another Matrix or List". Also, Vince Faller's response to you about Lag functions on matrices contains several examples.

You should read the sections on lists, matrices and associative arrays.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Using Match on a matrix without loop

@gzmorgan0,

If you look through the example that you have pointed out, the only thing that is documented in that section is logical indexing. The concept of logical indexing is powerful and one approach of acheiving vectorization of code.

With almost every other language/ analytical platform be it R, Matlab , Python etc. there is tons of documentation and in-built functions that make it easy to write clean, vectorized code. You may already know how to do this, but provided this one limited example on logical indexing, I dont think is particularly efficient to write clean, fast code for all needs.

Please try and google "Vectorized Code in JMP", all I get is this (https://community.jmp.com/t5/JMP-Blog/JSL-Tip-Use-Matrices-Instead-of-Lists/ba-p/29773). Please repeat the exercise for any of the other languages I have mentioned above and see how much wealth of information is made available to you. It is easy to write off my request, however I think it will serve our community and its users well if there is more documentation that goes deep into a couple of examples and addresses a few common problems.

Best

Uday

Uday