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