To put value in the specific column of uitable

조회 수: 2 (최근 30일)
yue ishida
yue ishida 2011년 12월 20일
A uitable is constructed like this:
a=[1 2 3 0;1 2 4 5;0 9 7 0;1 3 4 6]; a=num2cell(a)
First the matrix is like this:
1 2 3 0
1 2 4 5
0 9 7 0
1 3 4 6
Therefore I need to construct the code based on the algorithm below:
1.In first row, I need to check either the value in end column is zero or not. If the value is zero,I need to shift the end column into previous column. If the element is zero again,the operation will proceed again, else the end column will fix.
2. In the end column, the value 55 will replace the current value.
3. This process will proceed to next row.
Finally,the matrix will become like this:
1 2 55 0
1 2 4 55
0 9 55 0
1 3 4 55
I need help to solve this problem. Thank you very much for your concern.
  댓글 수: 4
Walter Roberson
Walter Roberson 2011년 12월 20일
So the rule is just "Change the last non-zero entry in the column to the value 55" ?
yue ishida
yue ishida 2011년 12월 20일
Yes.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 12월 20일
s = size(a);
j1 = arrayfun(@(x)find(a(x,:),1,'last'),1:s(1));
a(sub2ind(s,1:s(1),j1)) = 55;
OR if a - cell array
a1 = cellfun(@(x)x>0,a);
a(fliplr(cumsum(a1(:,end:-1:1),2))==1 & a1) = {55};

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by