I need to sort the vector Codes and I need the values of vector Discharge to be ordinated according to it. I tried the function sortrows but in this case it doesn't work since in soe cases I'm not working with scalars.

6 件のコメント

Walter Roberson
Walter Roberson 2021 年 8 月 7 日
What does it mean to sort Codes when Codes contains a mix of scalars and vectors?
How should be code 0 in row 10 be sorted relative to the 0 that is in the second element of row 3?
Chiara Scarpellini
Chiara Scarpellini 2021 年 8 月 7 日
Name_Code = table(IDs, C, D, 'VariableNames',["Name" "Codes" "Discharge"]);
Name_Code.Codes=cellfun(@sort,Name_Code.Codes,"UniformOutput",false)
for example if I use this commands I+m able to sort the vectors in the Codes column, I would need a function that tells me how to keep the same order in the column Discharge
Walter Roberson
Walter Roberson 2021 年 8 月 7 日
Use a for loop and the second output of sort.
Chiara Scarpellini
Chiara Scarpellini 2021 年 8 月 7 日
I tried but it wasn't working
Walter Roberson
Walter Roberson 2021 年 8 月 7 日
編集済み: Walter Roberson 2021 年 8 月 8 日
[Name_Code.Codes, Cidx] = cellfun(@sort,Name_Code.Codes,"UniformOutput",false);
Name_Code.Discharge = cellfun(@(d,idx)d(idx), Name_Code.Discharge, Cidx);
Chiara Scarpellini
Chiara Scarpellini 2021 年 8 月 7 日
it works! huge thank you!

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

 採用された回答

Walter Roberson
Walter Roberson 2021 年 8 月 8 日

0 投票

(Moving down from comment)
[Name_Code.Codes, Cidx] = cellfun(@sort,Name_Code.Codes,"UniformOutput",false);
Name_Code.Discharge = cellfun(@(d,idx)d(idx), Name_Code.Discharge, Cidx);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by