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

4 Ansichten (letzte 30 Tage)
I want to set A(i,j) = 0 if both i and j are odd. Is this possible to do vectorially?

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 15 Feb. 2023
%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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by