# Thread: extracting data from matlab data structures

1. ## 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.

2. Originally Posted by 2clients
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

3. Try:

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

4. Originally Posted by CaptainBlack
IIRC:

xx=data.StartLat

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

Cb

5. Originally Posted by elbarto
Try:

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

That worked perfectly! Thank you!