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

4 ビュー (過去 30 日間)
L'O.G.
L'O.G. 2023 年 2 月 15 日
回答済み: Dyuman Joshi 2023 年 2 月 15 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by