NEED HELP ON MATRIX MANIPULATIONS

1 次查看(过去 30 天)
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