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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:08:22+00:00 2026-06-09T02:08:22+00:00

I have an array of 100K structs. I am listing below the contents of

  • 0

I have an array of 100K structs. I am listing below the contents of one such struct:

Iteration:1

BlockID:86

The BlockID can have values between 1 and 100. I want to find out the count of occurrences of BlockID. For eg.: BlockID “1” occurred 25 times; BlockID “98” occurred 58 times and so on.

I looked online and tried the options mentioned in these links, but could not get a solution:
Matlab: Count number of structs that have a specific content
how to count unique elements of a cell in matlab?
Matlab: How to calculate how many unique strings are stored in the cell?

  • 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-09T02:08:23+00:00Added an answer on June 9, 2026 at 2:08 am

    You can use arrayfun and count_unique (count_unique is not an official function – it’s from the matlab central file exchange and can be found here):

    ids= arrayfun(@(x)x.BlockID, struct1);
    [vals, counts] = count_unique(ids);
    

    NB: As pointed out by rody_o (though he/she missed the fact that the indexing is unnecessary) there is an alternative way to concatenate the, ids, namely

    ids = [struct1.BlockID];
    

    Alternatively you could create your own count_unique function if you wished,

    function [counts, uns] = count_unique(ids)
    uns= unique(ids);
    counts = arrayfun(@(x)sum(ids == x), uns);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some 100k values. When I plot them as a line in R
i have array like below which is sorted by array_count_values function, Array ( [Session
I have array and contains 50 values , example [ 'london', 'bluehit', 'green', 'lonpark',
I have array of keywords. How can I find if any of these keywords
I have array with times like below 00:00, 01:25, 02:00, 02:35, 04:35, 05:00, 06:00,
I have array like below: Array ( [_edit_lock] => Array ( [0] => 1309611144:1
I have array like below, Array ( [14289] => Array ( [0] => Karthikeyan
I have array of objects MyClass MyArr[10]; In method of one element of array
Imagine I have array of values ranging from 1 to 24. I want to
Suppose you have a sorted range (x to y) of values in an array.

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.