필터 지우기
필터 지우기

could anyone help me how to select the partitions in a random manner.

조회 수: 2 (최근 30일)
jaah navi
jaah navi 2019년 4월 15일
댓글: jaah navi 2019년 4월 15일
Code:
X=[3];
A = partitions(X)
partdisp(A)
when i run the code it executes and gives the result in the following manner.
A = {1x1 cell}
{1x2 cell}
{1x2 cell}
{1x2 cell}
{1x3 cell}
The 5 partitions of set {1 2 3}:
{1 2 3}
{1 2} {3}
{1 3} {2}
{1} {2 3}
{1} {2} {3}
Among 5 partitions i want to select any one partition in a random manner.
So i tried with the following command rand(A)
But i got the error stating Size inputs must be numeric.
As each partition contains the set it's not in numeric form.I can understand it.But there should be some way of selecting it.
As i couldnt able to do it,coud anyone help me to solve it.

채택된 답변

KSSV
KSSV 2019년 4월 15일
N = length(A) ;
idx = randperm(N,1) ;
iwant = A{idx}
  댓글 수: 1
jaah navi
jaah navi 2019년 4월 15일
with respect to the code given by you i implemented it in the following code:
X=[3];
A = partitions(3)
partdisp(A)
S = length(A)
idx = randperm(S,1) ;
iwant = A{idx}
for d=1:length(iwant)
for e=1:length(iwant{d})
C=(iwant{d}{e})
end
end
When i run the code i am getting error stating
Cell contents reference from a non-cell array object.
for example
if iwant= [1x2 double] which means {13} {2}
then i need to have the display in following manner:
d should be 2
then e=1
C= 1 3
then e=2
C=2
could you please help me to get this.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by