create an array

1 次查看(过去 30 天)
Hassan
Hassan 2011-6-30
I wonder how I can make an array (200,400) with values 0 to 7 which randomly distributed? I apperciate your help.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2011-6-30
rand(200,400)*7
  2 个评论
Hassan
Hassan 2011-6-30
thanks Andrei. I wonder how I can group each value in the array. for eaxmple (1:20,1:20)=1,(40:70,40:70)=2 and so on.
Hassan
Hassan 2011-6-30
thanks but can you please show it with an example?

请先登录,再进行评论。

更多回答(1 个)

Sean de Wolski
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 个评论
Sean de Wolski
Sean de Wolski 2011-6-30
Nicer!
I don't think I've ever used arrayfun()
Hassan
Hassan 2011-6-30
thanks a lot Sean and Andrei.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by