Replacing zeros with other values

조회 수: 17 (최근 30일)
Mido
Mido 2016년 11월 3일
댓글: KSSV 2016년 11월 4일
A=[1 2 3 4;
4 5 0 0;
1 0 0 1;
0 1 1 1]
I want to replace zeros in the third column with last known values. The result should be
A=[1 2 3 4;
4 5 3 0;
1 0 3 1;
0 1 1 1]
What should be the code.

채택된 답변

KSSV
KSSV 2016년 11월 4일
A3=A(:,3);
A3(A3==0)=3;
A(:,3)=A3;
  댓글 수: 6
Mido
Mido 2016년 11월 4일
I have one more question. If I have a matrix like this
A= [1 1;
1 2;
1 3;
1 4;
2 1;
2 2;
2 3;
2 4]
I want to extract rows from the matrix as follows: For each different number in the first column extract rows using increment of 2 in the second column. The result will be:
A= [1 2;
1 4;
2 2;
2 4]
KSSV
KSSV 2016년 11월 4일
A(2:2:end,:)

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by