I have coding as below.
a=[11 11 33 33 22 44; 33 33 33 11 11 22; 33 33 11 22 22 44; 44 44 33 22 44 11]
s = size(a);
b = zeros(s);
b(abs(a - 33) < 1e3*eps) = -10;
k = [true(s(1),1) diff(a,1,2)~=0].*a;
p = arrayfun(@(x)10*nnz(strfind(k(x,:),[33 22])),(1:s(1))');
penalty = sum(b,2) + p;
The coding is need to fulfil below conditions and cannot overlap each other:
pattern | penalty
33 33 33 | -30
33 33 22 | -20
33 11 | -10
33 33 22 | -10
33 22 | 0
Therefore, I need your help to check and correct this coding. Thank you.

 採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 1 月 2 日

0 投票

try this is code:
s = size(a);
b = zeros(s);
b(abs(a - 33) < 1e3*eps) = -10;
p = arrayfun(@(x)10*nnz(strfind(a(x,:),[33 22])),(1:s(1))');
penalty = sum(b,2) + p;

4 件のコメント

yue ishida
yue ishida 2012 年 1 月 3 日
A is undefined... How to define A? I don't know how, so please help me.
Walter Roberson
Walter Roberson 2012 年 1 月 3 日
Use "a" instead of "A".
Andrei Bobrov
Andrei Bobrov 2012 年 1 月 3 日
Thank you Walter, corrected.
yue ishida
yue ishida 2012 年 1 月 3 日
Yes, thank you very much...

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

その他の回答 (0 件)

カテゴリ

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

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by