Find the max/min values within determined segments of a matrix
Mostra commenti meno recenti
For two matrices A and B:
A = [1 2 3; 4 5 6; 7 8 9; 10 11 12];
B = [3 5 8; 3 1 2; 1 5 2; 5 8 0];
For certain segments in A, I want to get the highest values related values in B. For this example, dividing the matrix into segments every 2 values of A, the output should be:
A = [1 2 3; 4 5 6; 7 8 9; 10 11 12];
Bmax = [5 5 8; 8 2 2; 5 5 5; 5 8 8];
Bmin = [3 3 3; 3 1 1; 1 1 2; 2 0 0];
To clarify the example, for values of A between 5 and 6, the maximum values of A where 2, while the minimum where 1.
Look into the comments below to get more information on the reasons for asking this question.
Thanks!
5 Commenti
Hamoon
il 12 Set 2015
Could you explain these things:
1. Why did you define a 4*3 matrix for "A" but you are using A(:) in your code which is a 12*1 vector?
2. Why the output of your example is simply like this:
Bbins_max = max(B,[],2);
Bbins_min = min(B,[],2);
that means it's the maximum and minimum values of B's columns.
3. Is there any special concept behind these things?
Victor Francisco Pajuelo Madrigal
il 13 Set 2015
Modificato: Victor Francisco Pajuelo Madrigal
il 13 Set 2015
Victor Francisco Pajuelo Madrigal
il 13 Set 2015
Modificato: Victor Francisco Pajuelo Madrigal
il 14 Set 2015
Hamoon
il 14 Set 2015
Well, I hoped you'd say something about your data, and the reasons you are doing this. Actually it's not about Matlab, it's about what you want to do and how you want to do it, and the programming part of that is not an issue here. It's not hard to calculate maximum and minimum of B in that ranges, when you found that ranges you can white this into your loop:
IndexB = B<=val1 & B>=val0;
B_max_current = max(B(IndexB));
B_min_current = min(B(IndexB));
But I don't think that's your problem. It would be better if you talked about your database and the reason you're doing this. Then it's possible someone brings up with some ideas and algorithms to help you on this.
Victor Francisco Pajuelo Madrigal
il 14 Set 2015
Modificato: Victor Francisco Pajuelo Madrigal
il 14 Set 2015
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Material Sciences in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


