MATLAB Answers

0

Hello everyone, I am stuck in a question. Can anyone there help me out? The question is as follows-

Asked by SUDIPTA MUKHERJEE on 15 Jun 2018
Latest activity Commented on by SUDIPTA MUKHERJEE on 23 Jun 2018
Accepted Answer by KSSV
I have a 3D matrix in which each 2D submatrix is of size 7×4.I have to randomly select any 4 out of these 7 rows(for various 3D indexes) except 1 row which will be decided by user input.That means, I can't select that particular row while selecting 4 rows. Thanks in advance.

  0 Comments

Sign in to comment.

1 Answer

Answer by KSSV
on 15 Jun 2018
 Accepted Answer

A = rand(7,4) ;
NS = 2 ; %Don't select his row
idx = randperm(7,5) ; % random indices of row
idx = setdiff(idx,NS) ; % remove NS if present
S = idx(1:4) ; % select these rows
iwant = A(S,:)

  4 Comments

Show 1 older comment
Bro, now I am stuck in one more situation of the same problem. Can you help me out. Now, I have to randomly select 4 rows for all the 7 iterations(i.e for each & every 2D row). The set of rows which are to be selected for each iteration(of different 2D indexes) must be unique.How do I do this? Thanks in advance.
How many iterations? If you have enough iterations then you would have to repeat.

Sign in to comment.