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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:41:56+00:00 2026-05-25T00:41:56+00:00

I have structure with 10 fields of the same size. The structure was read

  • 0

I have structure with 10 fields of the same size. The structure was read from a data file.

dataFile = ezread('myFile','\t');

I get a specific field (double) and produce an index array for all rows which are bigger than 2.

a_field = dataFile.a_field;
a = ismember(a_field,2:1000)

I could use ‘a’ to get all rows from another field where ‘a_field’ is bigger than 2. But how can I filter the complete structure? I would like to have a new structure which holds all rows from all fields where ‘a_field’ is bigger than 2.

It’s a basic question, but I can’t find an easy way around.

  • 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-25T00:41:56+00:00Added an answer on May 25, 2026 at 12:41 am

    Structures store their fields separately, so you have to go and apply your filter to each.

    For example, consider the following structure

    %# a sample structure
    dataFile.a_field = randn(20,1) + 1;
    dataFile.b_field = num2str((1:20)','string %d');  %'
    dataFile.c_field = rand(20,1);
    
    %# find rows where 'a_field' is bigger than 2
    idx = dataFile.a_field > 2;
    

    Now you have two options to filter the other fields:

    1) structfun

    use STRUCTFUN to apply your filtering function on each field:

    data2 = structfun(@(x) x(idx), dataFile, 'UniformOutput',false);
    

    2) FOR-loop + dynamic field names

    write an explicit for-loop, and use dynamic field names to access each:

    fn = fieldnames(dataFile);
    for i=1:numel(fn)
        data2.(fn{i}) = dataFile.(fn{i})(idx);
    end
    

    3) cellarrays

    Alternatively, we could convert the stucture to a cellarray, then apply the slicing to the entire thing:

    %# cellarray
    C = struct2cell(dataFile);
    C = [num2cell(C{1}) cellstr(C{2}) num2cell(C{3})];
    
    %# filter rows from all columns
    idx = vertcat(C{:,1}) > 2;
    C_filtered = C(idx,:)
    

    The result in this case:

    >> C_filtered
    C_filtered = 
        [3.0034]    ' string 5'    [ 0.53406]
        [2.4158]    'string 11'    [ 0.18971]
        [2.0289]    'string 13'    [ 0.14761]
        [ 2.458]    'string 14'    [0.054974]
        [2.7463]    'string 16'    [ 0.56056]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure which has 3 identifier fields and one value field. I
I have the following casting problem when my data structure sSpecificData contains a field
I have 14 tables that describe a hierarchical XML data structure. One field is
I have three similar tables with same fields and one field has same values.
Given that I have this resultset structure (superfluous fields have been stripped) Id |
I have a table (session_comments) with the following fields structure: student_id (foreign key to
I have a database structure that has a Person table which contains fields such
I have the following class structure FlowerDAO with the fields (mapped using Hibernate): id
I have the following MySQL table structure: num field company phone website 1 Gas
I have 2 structures that have 90% of their fields the same. I want

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.