Create a matrix (24,72) using 'for' loop.

9 ビュー (過去 30 日間)
ET-TAOUSSI mehdi
ET-TAOUSSI mehdi 2016 年 1 月 15 日
コメント済み: ET-TAOUSSI mehdi 2016 年 1 月 16 日
How can I use the loop 'for' or other, to produce the same matrix (24,72) depicted in the figure? kind regards.

採用された回答

Joseph Cheng
Joseph Cheng 2016 年 1 月 15 日
編集済み: Joseph Cheng 2016 年 1 月 15 日
since it is a nice simple pattern of (zeros for columns that are a multiple of 3) then:
DesiredResult = ones(24,72);
DesiredResult(:,3:3:end)=0;
  1 件のコメント
ET-TAOUSSI mehdi
ET-TAOUSSI mehdi 2016 年 1 月 16 日

Nice solution thank you Joseph Cheng.

サインインしてコメントする。

その他の回答 (1 件)

Brendan Hamm
Brendan Hamm 2016 年 1 月 15 日
You could do this with a loop:
A = ones(24,72);
for k = 1:72
if rem(k,3) == 0
A(:,k) = 0;
end
end
or you could do this in one line:
A = repmat([1 1 0],24,72/3);
The latter is much faster and more elegant.
  1 件のコメント
ET-TAOUSSI mehdi
ET-TAOUSSI mehdi 2016 年 1 月 16 日
the last is a good solution, thank you Brendan Hamm.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by