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 5934971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:11:19+00:00 2026-05-22T15:11:19+00:00

ismember checks for cell-array or matrix elements. How do we check for string-numeric elements

  • 0

ismember checks for cell-array or matrix elements. How do we check for string-numeric elements together? Please see below:

cell1 = {'netincome' [1] ; 'equity' [2] }  ;

cell2 = { 'cogs' [2222] [1] ; 'equity' [3501] [2] ; 

          'equity' [3333] [1] ; 'netincome' [1751] [1] } ;

This fails ->ismember(cell1(:,[1 2]), cell2(:,[1 3]) % I know why it fails.

Is there any way to match string elements and numeric elements from 2 cells? I tried using ismember independently (cell2mat func was used) but still can’t hit the right answer. The desired answer is:

[1751 ; 3501] ; OR 'netincome' [1751] [1] ; 'equity' [3501] [2] 
  • 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-05-22T15:11:19+00:00Added an answer on May 22, 2026 at 3:11 pm

    I don’t think there’s any good built-in solution for this situation. The best one I can think up at the moment is to create two nested loops to compare all the rows of each cell array, using the function ISEQUAL to do the comparisons:

    index = zeros(size(cell1,1),1);
    for row1 = 1:size(cell1,1)
      for row2 = 1:size(cell2,1)
        if isequal(cell1(row1,:),cell2(row2,[1 3]))
          index(row1) = row2;
          break
        end
      end
    end
    

    The result will be a set of match indices in the N-by-1 vector index, where N is the number of rows in cell1. If a row of cell1 can’t be matched to the data in any row of cell2, then the corresponding entry of index will be 0. Indices of matches in index will preserve the original order of the data in cell1. Also, this code ignores multiple matches in cell2, returning only the index of the first match found and breaking the inner loop (which will potentially reduce the number of iterations needed).

    Now you can index into cell2 to get the data corresponding to what’s in cell1:

    >> cell2(index,:)
    
    ans = 
    
        'netincome'    [1751]    [1]
        'equity'       [3501]    [2]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two cell arrays of strings, and I want to check if they
How to define a function is_member() that takes a value (i.e. a number, string,
The following command returns 1: ismember(-0.6, -1:.1:.9) but this next command returns 0: ismember(-0.1,
What is the difference between the isKind(of aClass: AnyClass) and the isMember(of aClass: AnyClass)
The below GUI simply lists some data in a listbox, plots it, and gives
I have two cells with the first column as string. I am currently using
I am facing a problem in matching elements in 2 matrices. The first element
I know that it fails at strcmp. I've provided operator< below, which calls strcmp.
I have the following code which check password/login and do other actions: public virtual
Leading on from a previous question FCM Clustering numeric data and csv/excel file Im

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.