필터 지우기
필터 지우기

how change elements around the special element in matrix

조회 수: 4 (최근 30일)
fatema saba
fatema saba 2015년 11월 11일
댓글: fatema saba 2015년 11월 11일
Hello please guide me.
A is
A=zeros(100,100)
i a j is selected randomly for example i=9 and j=8. I want to change element of matrix A to 1 on the basis of i and j. In fact elements that are around the element(i=9,j=8) should be changed to 1. my picture shows that. yellow cell is (i=9,j=8) and orange cells should be changed. each time i and j may be changed and this will change everything. Thank you

채택된 답변

Image Analyst
Image Analyst 2015년 11월 11일
Try this:
A(i-3:i+3, j-3:j+3) = 1; % Or whatever value you want.
If you want to change just the surrounding values and not the i,j value, then save it and restore it:
savedValue = A(i,j);
A(i-3:i+3, j-3:j+3) = 1; % Or whatever value you want.
A(i,j) = savedValue;
  댓글 수: 3
fatema saba
fatema saba 2015년 11월 11일
But if i and j point to element that is located on the border of matrix A, this makes some problem.
fatema saba
fatema saba 2015년 11월 11일
Thank you. I got it

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by