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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:08:02+00:00 2026-05-26T09:08:02+00:00

I have a structure with fields ID , Coor , Misc , Conn .

  • 0

I have a structure with fields ID,Coor,Misc,Conn. ID and Misc are doubles, however, Coor is a 1×3 vector and Conn is a 1xn vector (where n can theoretically be from 0 to inf).

Point(x).ID = [x]
Point(x).Coordinate = [xPos yPos zPos]
Point(x).Misc = [randomDouble]
Point(x).Conn = [someVectorOfNumbers]

I would like to have this mapped on a cell array, without using a FOR loop.

An example of the output:

'ID    xPos    yPos    zPos    Misc    Conn'
 1      0        0       0       0    '0 1 2'
 2      1        1       1       1      ''     
 ...
 x      x        x       x       x      '2'

Notice that Point.Conn, its vector of numbers gets converted into a string.

The issues that I am having is breaking up Point.Coordinate into its three elements, and converting Point.Conn into a string.

I feel like this can be done using struct2Cell and then changing the nesting level. I’m just not exactly sure how to do that.

  • 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-26T09:08:02+00:00Added an answer on May 26, 2026 at 9:08 am

    First make some example data:

    n = 10;
    
    ID         = num2cell(randperm(n)');
    Coordinate = mat2cell(randn(n, 3), ones(n,1));
    Misc       = num2cell(randn(n,1));
    Conn       = arrayfun(@randperm, randperm(n), 'UniformOutput', 0)';
    
    Point = struct('ID', ID, 'Coordinate', Coordinate, 'Misc', Misc, 'Conn', Conn);
    

    Now inspect it:

    >> Point
    
    Point = 
    
    10x1 struct array with fields:
        ID
        Coordinate
        Misc
        Conn
    
    >> Point(1)
    
    ans = 
    
                ID: 7
        Coordinate: [-0.0571 -1.1645 2.4124]
              Misc: 0.0524
              Conn: [3 2 1]
    

    Now use arrayfun() to sweep through the elements of structure array Point. We define a generic function x to operate on each element of Point, formatting the row like you described:

    Point_cell = arrayfun(@(x) [num2cell([x.ID x.Coordinate x.Misc]) num2str(x.Conn)], Point, 'UniformOutput', 0);
    Point_cell = vertcat(Point_cell{:})
    

    Now inspect the output:

    ans = 
    
        [ 7]    [-0.0571]    [-1.1645]    [ 2.4124]    [ 0.0524]    '3  2  1'            
        [ 5]    [ 0.2918]    [ 0.4948]    [ 0.7402]    [-1.9539]    '1  2'               
        [ 3]    [-0.6146]    [-1.2158]    [ 0.3097]    [ 0.5654]    '3  4  1  2'         
        [10]    [-0.0136]    [ 1.5908]    [-0.5420]    [ 0.0778]              [1x25 char]
        [ 2]    [ 0.4121]    [ 0.5265]    [ 0.1223]    [ 0.0807]              [1x22 char]
        [ 1]    [-0.9371]    [ 0.2648]    [ 0.9623]    [ 0.7947]    '1  2  5  4  3'      
        [ 4]    [ 0.8352]    [-0.3936]    [-0.2540]    [ 1.0437]    '6  2  3  7  4  1  5'
        [ 8]    [ 1.0945]    [-2.1763]    [ 1.8918]    [ 0.8022]    '1'                  
        [ 6]    [ 0.3212]    [-1.1957]    [-1.2203]    [-0.4688]              [1x37 char]
        [ 9]    [ 0.0151]    [ 0.3653]    [-0.3762]    [-0.0466]    '3  5  4  2  6  1'   
    

    Couldn’t tell from your question, but if you want all the numeric fields as an array inside a single cell, that is an easy tweak to do. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have this resultset structure (superfluous fields have been stripped) Id |
I have a structure which has 3 identifier fields and one value field. I
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 a tree-style database with the following structure: Table fields: NodeID int ParentID
I have a structure array containing fields as structure arrays of varying length. For
I have an array of structures, each structure with fields 'input' and 'output'. Input
I have a structure that has both :id and a :group_id fields. I wish
Hello i have tree structure in sql. Logics is standard: SomeID, ParentID, other fields.

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.