create an array
古いコメントを表示
I wonder how I can make an array (200,400) with values 0 to 7 which randomly distributed? I apperciate your help.
採用された回答
その他の回答 (1 件)
Sean de Wolski
2011 年 6 月 30 日
szs = [20 20 30]; %sizes
vals = [1 0 2]; %values
C = cellfun(@(c,v)ones(c)*v,num2cell(szs),num2cell(vals),'uni',false);
M = blkdiag(C{:});
3 件のコメント
Andrei Bobrov
2011 年 6 月 30 日
like
C = arrayfun(@(i1)ones(szs(i1))*vals(i1),1:3,'un',0);
Sean de Wolski
2011 年 6 月 30 日
Nicer!
I don't think I've ever used arrayfun()
Hassan
2011 年 6 月 30 日
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!