Path: news.mathworks.com!not-for-mail
From: "Jeff " <jea@gene.dot.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Cropping a range of data from the matrix
Date: Thu, 7 Jul 2011 21:47:09 +0000 (UTC)
Organization: Genentech Inc
Lines: 47
Message-ID: <iv59gt$ia2$1@newscl01ah.mathworks.com>
References: <471ec6cc-245d-4857-bbe1-a4d6cd9f1084@v7g2000vbk.googlegroups.com>
Reply-To: "Jeff " <jea@gene.dot.com>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1310075229 18754 172.30.248.35 (7 Jul 2011 21:47:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 7 Jul 2011 21:47:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1423763
Xref: news.mathworks.com comp.soft-sys.matlab:735451

Recep Ozdemir <recep.ozdemir64@gmail.com> wrote in message <471ec6cc-245d-4857-bbe1-a4d6cd9f1084@v7g2000vbk.googlegroups.com>...
> Hi everybody,
> 
> I am a beginner matlab user and I need your immediate help for the
> following case;
> 
> lets say I have an X matrix
> 
> X =
> 
>      1     2
>      2     4
>      3     6
>      4     8
>      5    10
>      6    12
>      7    14
>      8    16
>      9    18
>     10    20
> 
> I need to truncate this matrix and only need to obtain the values in
> column 1 when the values in column 2 are between "6" and "14"
> 
> So, in this case, my final matrix should be ;
> 
> X =
> 
>      3     6
>      4     8
>      5    10
>      6    12
>      7    14
> 
> Do you know which matlab commands should I have to use for this task
> 
> Thanks very much
> 
> Recep

If the values in column 1 are just an indexing of the rows, then you can just use:
idx = find(x(:,2) >= 6 & x(:,2) <=14);

If the values in column 1 aren't an index, use:
idx = (x(:,2) >= 6 & x(:,2) <=14);
out = idx .* x(:,1) ;
out2 = out(out > 0);