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

- JMP User Community
- :
- Discussions
- :
- Calculate a vector of miniums from a 2 dimentional matrix

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

Highlighted

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

Jun 4, 2020 10:09 AM
(757 views)

I am looking for a simple method to take a 2xn matrix and product a vector where each element in the vector is the minimum value for each row in the 2xn matrix

```
a=[ 1 4, 3 2, 5 6]
// the final result needs to be
[1, 2, 5]
```

Looping through matrix "a" can easily do this, but......I am hoping someone out there is more fluent in matrices that may have a more efficient solution

Jim

- Tags:
- matrix

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

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

Hi Jim,

```
m = [1 4, 3 2, 5 6];
v = Transpose( V Min( Transpose( m ) ) ); // VMin( m`)`
```

5 REPLIES 5

Highlighted

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

Hi Jim,

```
m = [1 4, 3 2, 5 6];
v = Transpose( V Min( Transpose( m ) ) ); // VMin( m`)`
```

Highlighted
##

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

Re: Calculate a vector of miniums from a 2 dimentional matrix

excellent...

Jim

Highlighted
##

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

Re: Calculate a vector of miniums from a 2 dimentional matrix

This set of functions all work on the vertical dimension of a matrix and can use the same technique to get a horizontal version.

Craige

Highlighted
##

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

Re: Calculate a vector of miniums from a 2 dimentional matrix

I knew there was a function but I couldn't find it, so I did it step by step using matrix operations. Touché @gzmorgan0 !

```
Names Default to Here( 1 );
// define 2xn data matrix
a = [ 1 4, 3 2, 5 6];
// compute row-wise differences as a vector
b = a[0,1] - a[0,2];
// determine deficit in first column of data matrix
c = b < 0;
// determine deficit in second column of data matrix
d = !c;
// create conforming matrix of deficits
e = c || d;
// multiply to get minimum value
f = a * e`;
// extract minimum value from diagonal elements
Vec Diag( f );
```

I doubt that my way is more efficient than iterating over the rows of the data matrix. I am sure it is not more efficient than V Min()!

Learn it once, use it forever!

Highlighted
##

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

Re: Calculate a vector of miniums from a 2 dimentional matrix

Wow! I hope you are doing @DonMcCormack 's challenges! I'm still going to need to work through that a bit longer.

Craige