필터 지우기
필터 지우기

How to delete n element from structure

조회 수: 4 (최근 30일)
priyanka
priyanka 2015년 2월 8일
댓글: Stephen23 2015년 2월 8일
How an element can be deleted from a structure. Structure is having only one field.
  댓글 수: 1
Erik S.
Erik S. 2015년 2월 8일
Can you give an example of your structure and its field?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2015년 2월 8일
% Make a structure with one field
% and an array in that field.
s.field1 = [1,2,3,4,5];
% Delete element 4 from the array in field1
s.field1(4) = []

추가 답변 (1개)

Stephen23
Stephen23 2015년 2월 8일
The original question "How an element can be deleted from a structure" also makes sense in the context of a non-scalar struct. In MATLAB, removing any element/s of the struct can be performed in exactly the same way as removing the elemtns of any other kind of array (numeric, char, etc):
>> A = struct('dat',{1,2,3,4});
>> A(3) = [];
OR
>> A = A([1,2,4]); % <- may be faster.
  댓글 수: 2
Image Analyst
Image Analyst 2015년 2월 8일
That creates an array of 4 structures, with each structure in the array having one field with one scalar value assigned to that field. That was not what I thought of. I thought of one structure with one field and an array assigned to that field. Hopefully the original poster will clarify which form it is.
Stephen23
Stephen23 2015년 2월 8일
I have always thought of struct(1:n).(...) as being a "structure array" in and of itself, rather than being an array containing structures. Indeed this is what the documentation is subtitled " struct...Create structure array", and give syntax as " struct(field,value) creates a structure array...".

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by