フィルターのクリア

Creating a matrix with values that increase cyclically

1 回表示 (過去 30 日間)
John Moseley
John Moseley 2013 年 12 月 28 日
コメント済み: John Moseley 2013 年 12 月 29 日
Hello,
I would like to create a matrix with two columns. The rows 1-670 would be 1,1; rows 671-1340 rows would be 1,2; rows 1341-2010 would be 1,3. And this trend would continue through the 670 rows of 1,256. After these rows, the next 670 rows would be 2,1; the next 670 rows would be 2,2; and the next 670 rows would be 2,3. So the trend is that every 670 rows, the second column increases by one. And every 670x256 rows, the first column increases by one and the second column resets at one.
Can someone please help with this? Any hints will be helpful.
Many thanks,
John

採用された回答

Roger Stafford
Roger Stafford 2013 年 12 月 28 日
An alternative to that is:
m = 256;
n = 670;
t = (.5:m^2*n-.5)'/n;
M = [floor(t/m),mod(floor(t),m)]+1;
  3 件のコメント
Roger Stafford
Roger Stafford 2013 年 12 月 28 日
m1 = 238;
m2 = 256;
n = 670;
followed by either this:
M = [reshape(repmat(1:m1,n*m2,1),[],1),...
reshape(repmat(repmat(1:m2,n,1),1,m1),[],1)];
or this:
t = (.5:m1*m2*n-.5)'/n;
M = [floor(t/m2),mod(floor(t),m2)]+1;
John Moseley
John Moseley 2013 年 12 月 29 日
Perfect. Thanks!

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

その他の回答 (1 件)

Roger Stafford
Roger Stafford 2013 年 12 月 28 日
M = [reshape(repmat(1:256,670*256,1),[],1),...
reshape(repmat(repmat(1:256,670,1),1,256),[],1)];

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by