필터 지우기
필터 지우기

How do you set entries in a matrix for odd rows with odd columns to zero?

조회 수: 4 (최근 30일)
I want to set A(i,j) = 0 if both i and j are odd. Is this possible to do vectorially?

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 2월 15일
%random data for example
A = rand(6,7)
A = 6×7
0.5610 0.2871 0.6280 0.3569 0.2765 0.5197 0.9541 0.3110 0.6573 0.3447 0.8105 0.0255 0.8263 0.2238 0.1450 0.6944 0.2345 0.6517 0.8826 0.6646 0.2389 0.0189 0.9227 0.6658 0.1392 0.9954 0.4346 0.1812 0.2084 0.3130 0.1589 0.8685 0.6272 0.6153 0.3176 0.9900 0.3501 0.1301 0.0931 0.5342 0.8533 0.5644
A(1:2:end,1:2:end)=0
A = 6×7
0 0.2871 0 0.3569 0 0.5197 0 0.3110 0.6573 0.3447 0.8105 0.0255 0.8263 0.2238 0 0.6944 0 0.6517 0 0.6646 0 0.0189 0.9227 0.6658 0.1392 0.9954 0.4346 0.1812 0 0.3130 0 0.8685 0 0.6153 0 0.9900 0.3501 0.1301 0.0931 0.5342 0.8533 0.5644

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by