Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
配列があるとしましょう
Y = [1, 2, 3, 4, 5, 6]
1つおきの数値を0に置き換える新しい配列を作成したいので、
y = [1, 0, 3, 0, 5, 0]
これにアプローチし、効率的な方法でこのためのコードを書くにはどうすればよいですか?
これはそれを行う必要があります:
Y(2:2:end) = 0;
この行では、基本的に、秒から最後までの各要素を2ステップでゼロにする必要があると言います。これは、より大きなステップでも実行できます。、Y(N:N:end) = 0すべてのN要素を0に等しくします。
Y(N:N:end) = 0
N