Discard elements from structure array

I have a structure with one field. I try to remove specific elements using i.e.:
trial(5).Hs_m = []
but the element remains in the structure, just having a value of "[]". Is there a way to remove it?

답변 (1개)

Massimo Zanetti
Massimo Zanetti 2017년 2월 25일
편집: Massimo Zanetti 2017년 2월 25일

0 개 추천

There is a specific function to remove a field from a structure: rmfield
Here is an example:
S.field1 = 'hello';
S.field2 = 456;
S
S =
struct with fields:
field1: 'hello'
field2: 456
Now remove one field:
S = rmfield(S,'field1')
S =
struct with fields:
field2: 456

댓글 수: 2

Chris
Chris 2017년 2월 25일
Thank you for the answer! I have to remove an element though, not a field! My structure has a length of 240 and I want to remove i.e. one, so to have up to trial(239).Hs_m
Massimo Zanetti
Massimo Zanetti 2017년 2월 25일
편집: Massimo Zanetti 2017년 2월 25일
So, why mentioning the field? In this case just remove the structure entry. Following your example, you can remove the 5-th entry with
trial(5) = []
regardless of the field(s).

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

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2017년 2월 25일

편집:

2017년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by