How to merge two matrix?

4 ビュー (過去 30 日間)
ASHA PON
ASHA PON 2022 年 4 月 17 日
コメント済み: ASHA PON 2022 年 4 月 18 日
Repeated values in a matrix are assigned to a group and now the elements in group has to be matched with another matrix having probability values of element in group.
For example
a=[6 6 5 6 5 6 6]
group 1 =5
3 5
group 2 = 6
1 2 4 6 7
b = [0.74 0.66 0.58 0.47 0.62 0.75 0.76]
Expecting output:
group 1 = 5
0.58 0.62
group 2 = 6
0.74 0.66 0.47 0.75 0.76
I need to apply the above mentioned problem to a larger number of group and n*m matrix. Kindly suggest me the procedure to apply for larger matrix.
Thank you in advance

採用された回答

KSSV
KSSV 2022 年 4 月 17 日
a=[6 6 5 6 5 6 6] ;
b = [0.74 0.66 0.58 0.47 0.62 0.75 0.76] ;
[c,ia,ib] = unique(a) ;
N = length(c) ;
G = cell(N,1) ;
iwant = cell(N,1) ;
for i = 1:N
G{i} = a(ib==i)
iwant{i} = b(ib==i)
end
G = 2×1 cell array
{[ 5 5]} {0×0 double}
iwant = 2×1 cell array
{[0.5800 0.6200]} {0×0 double }
G = 2×1 cell array
{[ 5 5]} {[6 6 6 6 6]}
iwant = 2×1 cell array
{[ 0.5800 0.6200]} {[0.7400 0.6600 0.4700 0.7500 0.7600]}
celldisp(G)
G{1} = 5 5 G{2} = 6 6 6 6 6
celldisp(iwant)
iwant{1} = 0.5800 0.6200 iwant{2} = 0.7400 0.6600 0.4700 0.7500 0.7600
  1 件のコメント
ASHA PON
ASHA PON 2022 年 4 月 18 日
Thank you so much for your reply. This is what i needed.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by