I need to create an array (256 x 256) in which elements increments using loops.

An array in which I(1,1) = 0 I(1,2) = 1 and so on till I(256,256) = 65535 using loops

2 件のコメント

Stephen23
Stephen23 2016 年 3 月 2 日
Why bother using loops? What a waste of MATLAB's abilities! The simplest, fastest, and neatest solution is to simply use reshape, as per Andrei Bobrov's last solution:
I = reshape(0:65535,256,[])';
Neha W
Neha W 2016 年 3 月 15 日
Thanks Sir.

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

 採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 3 月 2 日
I = zeros(256,256);
k = 0;
for i1 = 1:256
for i2 = 1:256
I(i1,i2) = k;
k = k + 1;
end
end
or
I = zeros(256,256);
k = 0;
for i1 = 1:numel(I)
I(i1) = k;
k = k + 1;
end
I = I';
or without loop
I = zeros(256,256);
I(:) = 0:numel(I) - 1;
I = I';
or
I = reshape(0:65535,256,[])';

1 件のコメント

Neha W
Neha W 2016 年 3 月 2 日
Thank you for your answer. It will really help me.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAerospace Blockset についてさらに検索

質問済み:

2016 年 3 月 2 日

コメント済み:

2016 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by