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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:23:20+00:00 2026-06-17T17:23:20+00:00

I have a struct that holds thousands of samples of data. Each data point

  • 0

I have a struct that holds thousands of samples of data. Each data point contains multiple objects. For example:

Structure(1).a = 7
Structure(1).b = 3
Structure(2).a = 2
Structure(2).b = 6
Structure(3).a = 1
Structure(3).b = 6
...
... (thousands more)
...
Structure(2345).a = 4
Structure(2345).b = 9

… and so on.

If I wanted to find the index number of all the ‘.b’ objects containing the number 6, I would have expected the following function would do the trick:

find(Structure.b == 6)

… and I would expect the answer to contain ‘2’ and ‘3’ (for the input shown above).

However, this doesn’t work. What is the correct syntax and/or could I be arranging my data in a more logical way in the first place?

  • 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-17T17:23:21+00:00Added an answer on June 17, 2026 at 5:23 pm

    The syntax Structure.b for an array of structs gives you a comma-separated list, so you’ll have to concatenate them all (for instance, using brackets []) in order to obtain a vector:

    find([Structure.b] == 6)
    

    For the input shown above, the result is as expected:

    ans =
         2     3
    

    As Jonas noted, this would work only if there are no fields containing empty matrices, because empty matrices will not be reflected in the concatenation result.

    Handling structs with empty fields

    If you suspect that these fields may contain empty matrices, either convert them to NaNs (if possible…) or consider using one of the safer solutions suggested by Rody.

    In addition, I’ve thought of another interesting workaround for this using strings. We can concatenate everything into a delimited string to keep the information about empty fields, and then tokenize it back (this, in my humble opinion, is easier to be done in MATLAB than handle numerical values stored in cells).

    Inspired by Jonas’ comment, we can convert empty fields to NaNs like so:

    str = sprintf('%f,', Structure.b)
    B = textscan(str, '%f', 'delimiter', ',', 'EmptyValue', NaN)
    

    and this allows you to apply find on the contents of B:

    find(B{:} == 6)
    
    ans =
         2
         3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::vector that holds a Point struct (x,y,z and some other non-pointer
I have a class that holds several vectors of objects: struct ComponentA { public:
I have a struct that contains three lists and an integer as can be
Let's say I have a struct that contains local environments: public struct Environments {
I have a struct-array that contains details of different reports that can be run.
I have a struct member that holds lots of string elements. What I want
I have a VECTOR struct that holds 3 integers, i, j, and k. I
I am trying to make a data tree that holds multiple data types and
I have a simple object that holds some [public] data. I want to keep
I have a fairly simple const struct in some C code that simply holds

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.