36877

Searching cell for string and return index number

Question:

I have a 20 x 2 cell. Both columns contains strings. What I would like to do is search for a string in column two and where the value in column 2 matches my search string to return the value in column 1. Please see my example below - I believe it will make things clearer.

name region ABC USA ASD EU PLKDD EU ERT EU LKK ASIA MNN USA WER EU

The result I would like based on the search string being "EU" is below

result ASD PLKDD ERT WER

Answer1:

You can try <a href="http://www.mathworks.se/help/matlab/ref/ismember.html" rel="nofollow">ismember</a>:

x = 'ABC' 'USA' 'ASD' 'EU' 'PLKDD' 'EU' 'ERT' 'EU' 'LKK' 'ASIA' 'MNN' 'USA' 'WER' 'EU' y = x(find(ismember(x(:,2), 'EU')),1) y = 'ASD' 'PLKDD' 'ERT' 'WER'

Recommend

  • NSControl isEnabled only available in OS X v10.0 through OS X v10.9
  • How to retrieve elements of OWL enumerated datatype expression?
  • @Primary equivalent for autowired Spring JPA repositories
  • How can I get the maximum number of OpenMP threads that may be created during the whole execution of
  • How to click on a link that has a certain content in puppeteer?
  • mysql and indexes with more than one column
  • Where in the relevant specification is it documented that some comments in a SQL script are, in fact
  • Reloading table causes flickering
  • How to add a filter to Active Admin dashboard?
  • Open hyperlink on click on an ggplot/plotly chart
  • How to merge two Request in Laravel
  • Getting IIS6 to play nice with WordPress Pretty Permalinks
  • Accessing local repository in offline mode
  • MarkLogic Node.js Sort on “last-modified”
  • Using extern @class in order to add a category?
  • c++ search a vector for element first seen position
  • Replace and retrieve placeholder value
  • getelement by class name for clicking
  • It is possible use the same sql azure instance from two different cloud service of two different sub
  • Getting error java.io.FileNotFoundException (log4j log file) at the time of publish project on cloud
  • Using android opencv apps without downloading opencv sdk manager
  • Efficient User-Agent Regex to find Safari in Python
  • Django Haystack Rebuild Index
  • Setting the run time properties on SpringApplicationBuilder()
  • jQuery: How to AJAXify WordPress Search?
  • How to install node-mysql?
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • Selenium to click on a javascript button corresponding to a text
  • Get specific string
  • What does 'Language neutral' mean with regard to MAKELANGID?
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • htaccess add www if not subdomain, if subdomain remove www
  • JSON response opens as a file, but I can't access it with JavaScript
  • Google Custom Search with transparent background
  • Insert into database using onclick function
  • What is Eclipse's Declaration View used for?
  • Accessing IRQ description array within a module and displaying action names
  • Can I make an Android app that runs a web view in Chrome 39?
  • When should I choose bucket sort over other sorting algorithms?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET