How to find the value before max value for vector for each 10 rows

2 vues (au cours des 30 derniers jours)
i have a vector , A=1:1:100
I want to find the values befor max values , so the result wii be, 9 19 29 39 49 59 69 79 89 99

Réponse acceptée

Karim
Karim le 29 Déc 2022
Hi see below for the stept to obtain such a vector
% set up the 'max row value indicator'
n = 10
n = 10
% create array A
A = 1:100
A = 1×100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
% reshape into a matrix with a given numeber of elements:
B = reshape(A, [], n)
B = 10×10
1 11 21 31 41 51 61 71 81 91 2 12 22 32 42 52 62 72 82 92 3 13 23 33 43 53 63 73 83 93 4 14 24 34 44 54 64 74 84 94 5 15 25 35 45 55 65 75 85 95 6 16 26 36 46 56 66 76 86 96 7 17 27 37 47 57 67 77 87 97 8 18 28 38 48 58 68 78 88 98 9 19 29 39 49 59 69 79 89 99 10 20 30 40 50 60 70 80 90 100
% find the max element for each group (which in this case has 10 elements),
% but we exclude the last (i.e. 10th) elements
maxval = max(B(1:end-1,:),[],1)
maxval = 1×10
9 19 29 39 49 59 69 79 89 99
  2 commentaires
abdullah al-dulaimi
abdullah al-dulaimi le 29 Déc 2022
maxval =
0×100 empty double matrix? i gent this comment
abdullah al-dulaimi
abdullah al-dulaimi le 29 Déc 2022
solved, thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by