Results 1 to 5 of 5

Math Help - extracting data from matlab data structures

  1. #1
    Junior Member
    Joined
    Aug 2008
    Posts
    38

    extracting data from matlab data structures

    I'm learning Matlab and just came across data structures for the first time.

    I have a data structure vector "data" = <1x131 cell> that is 131 sets long of these variable six fields:

    StartLat: 38.6890
    StartLon: 234.2153
    EndLat: 38.3359
    EndLon: 232.9991
    StartDate: 733857
    EndDate: 733976

    How do I extract all the StartLat values into one 1x131 vector, or what if I wanted say the 4th and 6th together?

    I've used data{1:n} to just pull certain sets, but I can't figure out how to pull the variables out of the structure.

    Thank you and have a nice day.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by 2clients View Post
    I'm learning Matlab and just came across data structures for the first time.

    I have a data structure vector "data" = <1x131 cell> that is 131 sets long of these variable six fields:

    StartLat: 38.6890
    StartLon: 234.2153
    EndLat: 38.3359
    EndLon: 232.9991
    StartDate: 733857
    EndDate: 733976

    How do I extract all the StartLat values into one 1x131 vector, or what if I wanted say the 4th and 6th together?

    I've used data{1:n} to just pull certain sets, but I can't figure out how to pull the variables out of the structure.

    Thank you and have a nice day.
    IIRC:

    xx=data.StartLat

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    Try:

    Code:
    cellfun(@(x)x.StartLat,data)
    Elbarto
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by CaptainBlack View Post
    IIRC:

    xx=data.StartLat

    CB
    Unfortunatly this does not extract the data in a manner that is of much use.

    Cb
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Aug 2008
    Posts
    38
    Quote Originally Posted by elbarto View Post
    Try:

    Code:
    cellfun(@(x)x.StartLat,data)
    Elbarto

    That worked perfectly! Thank you!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. [SOLVED] Interpolating z(x,y) data point from 4 data points (rectangular)?
    Posted in the Advanced Applied Math Forum
    Replies: 2
    Last Post: June 20th 2011, 06:04 PM
  2. Replies: 2
    Last Post: July 6th 2010, 06:33 PM
  3. Loading Data in Matlab
    Posted in the Math Software Forum
    Replies: 3
    Last Post: May 7th 2009, 08:06 PM
  4. importing data into octave/matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: November 5th 2008, 09:20 AM
  5. Saving data (Matlab Question)
    Posted in the Math Software Forum
    Replies: 2
    Last Post: June 23rd 2008, 08:00 AM

Search Tags


/mathhelpforum @mathhelpforum