필터 지우기
필터 지우기

Fill a border of a matrix with 0's

조회 수: 29 (최근 30일)
Jhangir
Jhangir 2013년 11월 6일
편집: Image Analyst 2013년 11월 6일
Lets say I have a matrix A. I want to replace all the values at the border meaning, the first row, the last row, the first column, and the last column with 0s, How do I do this

채택된 답변

Image Analyst
Image Analyst 2013년 11월 6일
Try this:
grayImage(1,:) = 0;
grayImage(end,:) = 0;
grayImage(:,1) = 0;
grayImage(:,end) = 0;
Related, if you want to add a layer of 0's all the way around, you can use padarray() if you have the Image Processing Toolbox:
paddedImage = padarray(grayImage,[1 1]);
  댓글 수: 2
Jhangir
Jhangir 2013년 11월 6일
[n,m]=size(R);
R(1,:)=0;,R(n,:)=0;,R(:,1)=0;,R(:,m)=0;
I just did this I think it worked
Image Analyst
Image Analyst 2013년 11월 6일
편집: Image Analyst 2013년 11월 6일
Like I showed you "end" is a convenient way to get the last index of any dimension without actually having to use the size() function to determine what index value that would be.
And you don't need the commas in your code. For readability I're recommend putting them on separate lines.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by