Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: extract the rows except the specific index

$
0
0
On 12/28/2012 11:56 AM, uny gg wrote:
...
> I would like to extract the rows except the specific index..
> For example,
>
> A = (1,2,3;4,5,6;7,8,9;10,11,12;13,14,15;16,17,18) % 6 by 3 matrix.
>
> What I want to do is.. divide this matrix, 3 by 3 and 3 by 3 matrix
> randomly ... Here is what I try.
>
> bottom =1;
> top =6;
> ran_idx = bottom + (top - bottom)*rand([1,3]);
> ran_idx = ceil(ran_idx);

> train = A(ran_idx,:);
> test = A(~ran_idx.:); % this one is not working,, return. empty matrix..
>
> I can extract the train matrix.. but I could not make test..

b=1; t=6; n=3;
idx=randperm(t,n); % doc randperm
train = A(idx,:);
test=A(setdiff([t:b],idx),:); % doc setdiff and friends...

--

Viewing all articles
Browse latest Browse all 19628

Trending Articles