How to sort only nonzeros values of an array that is linked to cell array ?

1 回表示 (過去 30 日間)
Rachel Sabioni
Rachel Sabioni 2019 年 3 月 22 日
コメント済み: Rachel Sabioni 2019 年 3 月 22 日
Hello,
I did a combination between 5 elements (A, B, C, D, E). Each combination corresponds to a value. As shown below.
T =
6×3 cell array
{'A' } {'D'} {[ 0]}
{'B'} {'D'} {[ 0]}
{'C'} {'D'} {[ 0]}
{'A' } {'E' } {[ 0]}
{'B'} {'E' } {[6.008]}
{'C'} {'E' } {[4.385]}
Now I would like to sort in another matrix, with only non zeros values, by keeping the relation between number and combinations.
For example,
I need to extract 6.008 and I want that it shows that this numbers correponds to {'B'} and {'E' }
Could you help me ?
  3 件のコメント
Rachel Sabioni
Rachel Sabioni 2019 年 3 月 22 日
I want to sort just that:
{'B'} {'E' } {[6.008]}
{'C'} {'E' } {[4.385]}
Rachel Sabioni
Rachel Sabioni 2019 年 3 月 22 日
It means, all non zero values and their correspondant combinations

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

採用された回答

madhan ravi
madhan ravi 2019 年 3 月 22 日
[~,I] = sort(vertcat(T{:,3}));
sorted_T = T(I,:);
Corresponding_matche_s = T(vertcat(T{:,3})==6.008,:)
  6 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 22 日
編集済み: madhan ravi 2019 年 3 月 22 日
D = d( I, : );
New = D( cat( 1, D{:,3} ) < 5, : )
https://in.mathworks.com/learn/tutorials/matlab-onramp.html - please have a look at it , useful and free to learn Matlab.
Rachel Sabioni
Rachel Sabioni 2019 年 3 月 22 日
Thanks. It worked.
However I would like to do that by using if loops, bcause I would like to insert many different conditions.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by