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

 採用された回答

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2020 年 2 月 20 日

1 投票

ZORD=sortrows(Z',4)';
[~,~,C]=unique(ZORD(end,:));
ZFIN=[ZORD; C']

1 件のコメント

Alejandro Fernández
Alejandro Fernández 2020 年 2 月 20 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索

製品

リリース

R2019b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by