To calculate value in a uitable

1 回表示 (過去 30 日間)
yue ishida
yue ishida 2011 年 12 月 21 日
In a uitable table, I have produce a matrix as below:
>> a= [1 1 1 2 2 3 3 3 4 ; 3 3 1 4 4 4 3 1 1; 3 3 2 4 1 1 1 3 2]
a =
1 1 1 2 2 3 3 3 4
3 3 1 4 4 4 3 1 1
3 3 2 4 1 1 1 3 2
Therefore,in each row, I need to calculate the marks occur based on conditions below:
1. if no 3 occur in three cells continuously therefore the mark charged is 30.
2. if no 3 occur in two cells continuously and then followed by no 1 in the next cell, the mark charged is -20.
3. if no 3 occur in a cell and then followed by no 1 in the next cell, the mark charged is -10.
4. if no 3 occur in two cells continuously and then followed by no 2 in the next cell, the mark charged is -20.
5. if no 3 occur in a cell and then followed by no 2 in the next cell, the mark charged is 0.
Then, in each row, the total marks will calculate. Finally the result will be save in a matrix like this:
marks =
-30
-30
-20
This marks also will total to become an X value as below:
X = -80
How can I code this problem in matlab? Please help me and thank you.

採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 12 月 21 日
try this code, I cant check now
s = size(a);
b = zeros(s);
b(abs(a - 3) < 1e3*eps) = -10;
k = [true(s(1),1) diff(a,1,2)~=0].*a;
p = arrayfun(@(x)10*nnz(strfind(k(x,:),[3 2])),(1:s(1))');
marks = sum(b,2) + p;
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2011 年 12 月 21 日
Hi Yue!
X = sum(marks);
yue ishida
yue ishida 2011 年 12 月 21 日
Thanks..

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by