Is there a version of STRUCTFUN that operates on structure fields that are matrices instead of scalars?
조회 수: 1 (최근 30일)
이전 댓글 표시
My structure S that has two fields A, and B, both of which are vectors. I would like to be able to index into the the structure to pick out any four elements, and find the unique elements in B.
For example, given the structure S defined by: S(1).A= [ 1 2] ; S(1).B= [ 2 4 1] ; S(2).A= [ 2 2] ; S(2).B= [ 2 1] ; S(3).A= [ 0 2] ; S(3).B= [ 5] ; S(4).A= [ 1 4] ; S(4).B= [ 1 4 3 10] ; S(5).A= [ 3 2] ; S(5).B= [ 2 4 7.5 9 11] ;
I would like to be able to say: VECTORSTRUCTFUN( @(x) union( x.B), S([1 2 4 5]))
and get [1 2 3 4 7.5 9 10 11] which are the union of the four vectors.
댓글 수: 0
답변 (1개)
Oleg Komarov
2011년 2월 9일
You should go a slightly different way:
S(1).A = [ 1 2];
S(1).B = [ 2 4 1];
S(2).A = [ 2 2];
S(2).B = [ 2 1];
S(3).A = [ 0 2];
S(3).B = [ 5];
S(4).A = [ 1 4];
S(4).B = [ 1 4 3 10];
S(5).A = [ 3 2];
S(5).B = [ 2 4 7.5 9 11];
% Retrieve unique values from the union of S(1).B, S(2).B, ...
unique([S([1 2 4 5]).B])
Oleg
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!