Add value in a matrix

4 visualizzazioni (ultimi 30 giorni)
Hi, I need to add a row of values to an array, taking into account the last row of my array (once sorted) I want the next row to show a number starting at 1 that is related to the previous row. Here is an example to try to explain it better
% First matrix
Z = [255 1 0 255 255 255 1
30 51 51 30 29 29 21
49 51 52 48 51 52 48
-5 4 4 -5 -4 -4 4];
% Orderly matrix in the 4th row
ZORD = [255 255 255 255 1 0 1
30 30 29 29 21 21 21
49 48 51 52 51 52 48
-5 -5 -4 -4 4 4 4];
% So far I know how to do it, but this is what I put in now is what
% I only know how to do with a for-loop but for my data size it is not very operational.
ZFIN = [255,255,255,255,1,0,1;
30,30,29,29,21,21,21;
49,48,51,52,51,52,48;
-5,-5,-4,-4,4,4,4;
1 1 2 2 3 3 3]
If someone knows how to do the last step I would be very grateful, thank you very much

Risposta accettata

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH il 20 Feb 2020
ZORD=sortrows(Z',4)';
[~,~,C]=unique(ZORD(end,:));
ZFIN=[ZORD; C']

Più risposte (0)

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by