Find minimum value within struct
조회 수: 16 (최근 30일)
이전 댓글 표시
Hi
I'm trying to determine the minimum value within a struct. I have a data struct with subfields which are timestamped. I'd like to find the smallest time, then reference all the other data accordingly.
example of the data:
- data.val1.time = something
- data.val2.time = something else
- .
- .
- data.valN.time = something else
I can think of a brute force way of doing it, but I'm thinking that there should be a nicer way.
anyone have any ideas?
댓글 수: 1
Jan
2011년 8월 3일
Are "val1", "val2", ... the real field names? Then I strongly recommend to use an array instead: val(1), val(2), ... This will make the conversion of the subfield .time much easier.
채택된 답변
추가 답변 (1개)
Sean de Wolski
2011년 8월 3일
min(structfun(@min,data));
is significantly faster on my machine. Conversions to and from cells take awhile.
댓글 수: 1
Jan
2011년 8월 3일
STRUCT2CELL is surprisingly fast, because the underlying representation is almost equivalent: Only the list of field names is different.
But CELL2MAT is slow, because it does not pre-allocate sufficiently. Anyhow, for 3 or 100 fields the speed will not be too important.
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!