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일

0 개 추천

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일

0 개 추천

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
Andrei Bobrov 2011년 6월 30일
like
C = arrayfun(@(i1)ones(szs(i1))*vals(i1),1:3,'un',0);
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2011년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by