Trim Matrix and find the min-max value the reshaped matrix

1 Ansicht (letzte 30 Tage)
Lila wagou
Lila wagou am 22 Mär. 2016
Kommentiert: Lila wagou am 22 Mär. 2016
Dear All; For a given Matrix (n : column, m : row) I want to trim [the 2, the 4 the 6 : paire column number] and find the index of min-max value in the reshaped (new) matrix, for example
A =
1 4 7 10
2 5 8 11
3 6 9 12
I trim the the 2 and the 4 column (keep the impair number ones)
B =
1 7
2 8
3 9
Min_value = 1 (index Column =1 row = 1)
Max_value = 9 (index Column =2 row = 3)
Or I trim the the 1 and the 3 column (keep the pair number ones)
C =
4 10
5 11
6 12
Min_value = 4 (index Column =1 row = 1)
Max_value = 12 (index Column =2 row = 3)

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 22 Mär. 2016
a=A(:,1:2:end)
| b=A(:,2:2:end)
[ii1,jj1]=min(a)
[ii2,jj2]=max(a)
[xx1,yy1]=min(b)
[xx2,yy2]=max(b)
  1 Kommentar
Lila wagou
Lila wagou am 22 Mär. 2016
Thank you Mr Azzi Abdelmalek it work for trim, i cannot understand for the min and the max i want the min and its position (in the new matrix) i want the max and its position (in the new matrix) Thank you again

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Stephen23
Stephen23 am 22 Mär. 2016
Here is how to get the maximum and its indices (change max to min for the minimum):
>> B = [1,7;2,8;3,9]
B =
1 7
2 8
3 9
>> [max_val,max_idx] = max(B(:));
>> [max_row,max_col] = ind2sub(size(B),max_idx)
max_row =
3
max_col =
2
>> max_val
max_val =
9

Kategorien

Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by