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

row selection from a matrix

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.

Best 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,:)