cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

minimum value in each column in several matrices

YA_10963798
10-Marble

minimum value in each column in several matrices

I hope you are doing well. 

I need to take this sheet a step further.  Now after we get 24 matrics . I need to find the minimum value in each column in each matrix. 

For example: matrix Linters 23 will have a matrix of the minimum values of each colunm . I tried to do it as follows but couldn't get what i want since it gives me the minimum in the whole matrix . I need  the minimum in each column in each matrix.

Like in excel you select the colunum and find the minimum in that column. Sorry for bothering you a lot. But I genuinely appreciate your help

YA_10963798_0-1715066551554.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

You could use a utility function which take a matrix as its input and returns a row vector with the minimum values of each column

Werner_E_0-1715080818034.png

You may apply this function to individual matrices of L.inters

Werner_E_1-1715080850819.png

Werner_E_2-1715080861472.png

or create a table with all 24 rows

Werner_E_3-1715080939841.png

 

You may create the very same table in on go, too

Werner_E_4-1715081107523.png

 

 

 

View solution in original post

8 REPLIES 8

You could use a utility function which take a matrix as its input and returns a row vector with the minimum values of each column

Werner_E_0-1715080818034.png

You may apply this function to individual matrices of L.inters

Werner_E_1-1715080850819.png

Werner_E_2-1715080861472.png

or create a table with all 24 rows

Werner_E_3-1715080939841.png

 

You may create the very same table in on go, too

Werner_E_4-1715081107523.png

 

 

 

Why I'm getting zeros here ?

Actually zeros mean the function doesn't apply in Linteres ...I want to get the minimum value except for zero. the nearest minimum value

I should get the minimum value of each column in each matrix 

YA_10963798_0-1717056933251.png

 

ttokoro
20-Turquoise
(To:YA_10963798)

 

Identity of L intes[1 are all 0. So, min are all 0. If max you get below.

image.png

image.png

If you want mimimum but not 0, select the next data by sorting. 0 data should appear each only one time is assumed.

ttokoro_0-1717067901431.png

 

image.png

thank you . that works 

what do you mean by next data?

you mean next minimum data or next data in column?

@ttokoro 

I guess you meant index O+1 instead of index 2 when you access the sorted column. 🙂

 

Unfortunately your approach would only work OK if its guaranteed that each column in each of the matrices contains exactly one zero. The approach fails if a columns contains no zero at all or more than one zero!

 

I guess you could fix this by using "match" to find the last zero value in each sorted column (you also would ave to use try..on error... to copy with the situation of no existing zero) and then grab the next vector element.

ttokoro
20-Turquoise
(To:Werner_E)

image.pngimage.png

Nice
Thank you so much


@YA_10963798 wrote:

Why I'm getting zeros here ?


This should be clear! Each matrix has at least one zero in each column and so the minimum of each column IS zero.

 

If you only want to consider positive values, you may have to write your own "min" function and use this instead of the built-in function.

BTW, you should not use a variable with name "min" as otherwise Prime may get confused and you may be unable use the "min" function or the time units "min" later.

 

Another approach could be to replace all zero values in the matrix by a large value (maybe the maximum of the matrix) before you apply the "min" function.

Here is this idea, achieved in a tricky way: The vectorized expression M=0 returns a matrix the same dimensions as M with 0's where M has positive values and 1's where M has a value of zero or below.  Multiplying this matrix with the maximum value in M and adding that matrix to M achieves the desired result.

Note that this approach does not ignore negative numbers - only zero values are ignored.

Werner_E_2-1717068852241.png

 

Top Tags