Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 2348

# Slice a Matlab Matrix (newbie question)

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
tmonteit
2 Solutions

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

Commented:
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

Tackle projects and never again get stuck behind a technical roadblock.