필터 지우기
필터 지우기

How to change the values of the corners in a matrix

조회 수: 12 (최근 30일)
N/A
N/A 2022년 4월 28일
답변: Chunru 2022년 4월 28일
Hi,
Lets say I have a 100 * 100 matrix filled with zeros and I need to change the 4 corners to the value 1. What would be the best way to alter it?

채택된 답변

Chunru
Chunru 2022년 4월 28일
a= zeros(10, 10); % smaller matrix for easy display
% for corners
a([1 end], [1 end]) = 1;
a
a = 10×10
1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by