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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics and Optimization についてさらに検索

製品

質問済み:

2019 年 12 月 16 日

コメント済み:

2019 年 12 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by