NEED HELP ON MATRIX MANIPULATIONS

조회 수: 1 (최근 30일)
anshuman mishra
anshuman mishra 2019년 12월 16일
댓글: anshuman mishra 2019년 12월 16일
Consider a matrix
A= 21 14 7 0
18 11 4 3
15 8 1 6
12 5 2 9
9 2 5 12
6 1 8 15
3 4 11 18
0 7 14 21
My objective is to reach from base value 0 to top value 0 as underlined for dynamic time warp algorithm traversal by parsing through the smallest element of each row.
A= 21 14 7 0
18 11 4 3
15 8 1 6
12 5 2 9
9 2 5 12
6 1 8 15
3 4 11 18
0 7 14 21
The cost assignment can be defined as find the smallest element in each column :
1| 21 14 7 0
0| 18 11 4 3
1| 15 8 1 6
0| 12 5 2 9
0| 9 2 5 12
1| 6 1 8 15
0| 3 4 11 18
1| 0 7 14 21
So cost= 1 0 1 0 0 1 0 1
Cost assignment concept:
assign 1 whenever there's a smallest single unique element in the row .
Assign 0 whenever no smallest element is present or when multiple smallest same elements are present in the same row or column,then first instance should be zero and next to be 1 i.e. for example
1| 20 15 10 5 0
1| 16 11 6 1 4
1| 12 7 2 3 8
0| 8 3 2 7 12
1| 4 1 6 11 16
1 | 0 5 10 15 20

채택된 답변

KSSV
KSSV 2019년 12월 16일
A = [ 21 14 7 0
18 11 4 3
15 8 1 6
12 5 2 9
9 2 5 12
6 1 8 15
3 4 11 18
0 7 14 21];
m = min(A,[],2) ;
cost = m == 0 | m == 1 ;
  댓글 수: 1
anshuman mishra
anshuman mishra 2019년 12월 16일
Thanks, That works fine for matrix A but fails for
1| 20 15 10 5 0
1| 16 11 6 1 4
1| 12 7 2 3 8
0| 8 3 2 7 12
1| 4 1 6 11 16
1 | 0 5 10 15 20
Here the the output from the code is 1 1 0 0 1 1
But i need output 1 1 0 1 1 1 i.e. only the two rows having same smallest element must be assigned value a single value 0 instead of 0 & 0
Im assuming you took only 1 & 0 into consideration instead my question was whenever you detect a single non repeatable smallest element in the rows then assign it as 1 & when same multiple repeatable elements in rows as in the above case then assign 0.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by