To calculate value in a uitable
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!