To calculate value in a uitable

2 vues (au cours des 30 derniers jours)
yue ishida
yue ishida le 21 Déc 2011
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.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 21 Déc 2011
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 commentaires
Andrei Bobrov
Andrei Bobrov le 21 Déc 2011
Hi Yue!
X = sum(marks);
yue ishida
yue ishida le 21 Déc 2011
Thanks..

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by