How to combine two matrix and extract value from one matrix to another matrix in same position?

조회 수: 5 (최근 30일)
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
Thank you in advance

답변 (1개)

Voss
Voss 2022년 3월 20일
a = [6 6 5 6 5 6 6];
b = [0.74 0.66 0.58 0.47 0.62 0.75 0.76];
group_1 = 5;
group_2 = 6;
b(a == group_1)
ans = 1×2
0.5800 0.6200
b(a == group_2)
ans = 1×5
0.7400 0.6600 0.4700 0.7500 0.7600
% Expecting output:
% group 1 = 5
% 0.58 0.62
% group 2 = 6
% 0.74 0.66 0.47 0.75 0.76
  댓글 수: 1
ASHA PON
ASHA PON 2022년 4월 5일
Thank you very much for the reply. Actually i just discussed the smaller version of my problem. 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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by