Solved

Slice a Matlab Matrix (newbie question)

Posted on 2009-12-17
2,260 Views
I have a 2col by 20,000 row matrix in matlab

A=
.1    7
.2    8
.3    7
.....
2.1   12
2.2   13

How do I slice matrix A so that matrix B contains only the pairings from A where col1>.3 and col1<2.1?

The matlab documentation talkes about how to do this with indexing.  But since this is a HUGE matrix, finding the indices will be difficult.
0
Question by:tmonteit

LVL 6

Accepted Solution

One solution below, probalby not the simplest one:
``````A([[A(:,1) >0.3] .* [A(:,2) < 2.1]]==1,:)
``````
0

LVL 15

Assisted Solution

Just another solution (probably the most obvious).

Indexing like this in Matlab is very fast even for the huge matrix. How huge is it by the way? I worked with millions records without much problems.

``````B=A(A(:,1)>0.3 & A(:,1)<2.1),:);
``````
0

Featured Post

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationâ€¦