Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:38:42+00:00 2026-06-08T01:38:42+00:00

A = {‘A’; ‘E’; ‘A’; ‘F’}; B = {‘A’;’B’;’C’;’D’;’E’; ‘F’}; I am trying to

  • 0
A = {'A'; 'E'; 'A'; 'F'};

B = {'A';'B';'C';'D';'E'; 'F'};

I am trying to get for each string in cell array A, the index that matches that string in cell array B. A will have repeated values, B will not.

find(ismember(B, A) == 1)

outputs

1
5
6 

but I want to get

1
5
1
6

preferably in a one liner. I can’t use strcmp instead of ismember either as the vectors are different sizes.

The vectors will actually contain date strings, and I need the index not a logical index matrix, I’m interested in the number not to use it for indexing.

How do I do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:38:43+00:00Added an answer on June 8, 2026 at 1:38 am

    You flip the arguments to ismember, and you use the second output argument:

    [~,loc]=ismember(A,B)
    
    loc =
    
         1
         5
         1
         6
    

    The second output tells you where the elements of A are in B.

    If you are working with very strict limits to how many lines you can have in your code, and are in no position to fire the manager who imposed such limitations, you may want to access the second output of ismember directly. In order to do this, you can create the following helper function that allows to directly access the i-th output of a function

    function out = accessIthOutput(fun,ii)
    %ACCESSITHOUTPUT returns the i-th output variable of the function call fun
    %
    % define fun as anonymous function with no input, e.g.
    % @()ismember(A,B)
    % where A and B are defined in your workspace
    %
    % Using the above example, you'd access the second output argument
    % of ismember by calling
    % loc = accessIthOutput(@()ismember(A,B),2)
    
    
    %# get the output
    [output{1:ii}] = fun();
    
    %# return the i-th element
    out = output{ii};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a RegEx expression that will successfully parse the following
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that
I am doing a simple coin flipping experiment for class that involves flipping a
This is how I get the tags of a body of text. var tags
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.