Clear Filters
Clear Filters

Trimming structure of Arrays

24 views (last 30 days)
Amir
Amir on 28 Sep 2011
Hi Guys
I have a structure like this:
Data =
dateTime: [4906x1 double]
aircraftLat: [4906x1 double]
aircraftLong: [4906x1 double]
aircraftMSL: [4906x1 double]
aircraftSpeed: [4906x1 double]
aircraftCourse: [4906x1 double]
gcsLat: [4906x1 double]
gcsLong: [4906x1 double]
gcsMSL: [4906x1 double]
antAz: [4906x1 double]
antEl: [4906x1 double]
rssi: [4906x1 double]
I'd like to take the first 5 elements of each array and remove. Is there a neat solution for this? Or would I have to go into each array eg. Data.aircraftLat(1:5) = [], etc.
Thanks
Amir

Accepted Answer

Jan
Jan on 28 Sep 2011
DataField = fieldnames(Data);
for iField = 1:numel(DataField)
aField = DataField{iField};
Data.(aField) = Data.(aField)(5:end);
end

More Answers (2)

TAB
TAB on 28 Sep 2011
Data=structfun(@(x) ( x(6:end) ), Data,'UniformOutput', false);

Daniel Shub
Daniel Shub on 28 Sep 2011
It looks like all you arrays are the same size. You may want to consider a structure array instead of a structure with lots of arrays. This way you could then just do:
Data = Data(6:end);
to remove the first 5 elements.

Categories

Find more on Structures in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!