MATLAB: Removing element from structure. structure array I want to remove a element from a 1×8 struct. Simply doing it equal to empty brackets its not enough. I want it to became 1×7 struct. Best Answer Why is it not enough? Can't you do% Create a structure array:for k = 1 : 8 myStruct(k).f1 = k; myStruct(k).f2 = 2 * k;end% Delete the 5th structure from the array.myStruct(5) = [];Works beautifully for me. Related SolutionsMATLAB: How to delete/copy (store) rows of a struct You can do as a regular array :myStruct; % 1x45 strcu-array% Split indexk = numel(myStruct) - 13;% Slice structuremyStruct(1:k) % first elements before kmyStruct((k+1):end); % last element, from k to end MATLAB: Indexing multiple values of an array of structures with a field that varies in length John - why not use arrayfun to grab the last element of each structure in your array A. Something like lastElements = arrayfun(@(x)x.vec(end),A);This seems to work for the following example % randomly choose the lengths of 100 vectors vecLengths = randi(42,100,1); % create A A = []; for k=1:length(vecLengths) A(k).vec = randi(255,1,vecLengths(k)); end % get the last element from each vector lastElements = arrayfun(@(x)x.vec(end),A); Related QuestionDelete a struct in a struct arrayFlatten structure array if values are identicalAssign value to array structureHow to work with function inputs which are structures with different fieldsHow to read data in 1*3 struct for one filed directlyStructure inside a while loop && pixel distance
Best Answer