Slice a Matlab Matrix (newbie question)

Posted on 2009-12-17
Last Modified: 2016-02-10
I have a 2col by 20,000 row matrix in matlab

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

    Open in new window

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

    Open in new window


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    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…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now