index returned array directly
조회 수: 8 (최근 30일)
이전 댓글 표시
I'm pretty sure the answer to this question is no but I'm hoping to be surprised. Is it possible to directly index a returned array without first assigning a variable? I created a simple trivial example below to explain what I mean.
Simple Example By variable assignment:
x = 1:10;
y = find( x>5 ); % y is a temporary variable
desired = y(1:2) % y1 is the desired matrix
Simple Example by Direct Index
x = 1:10;
desired = find( x>5 )[1:2] % 'suggested' code
To be clear the second line above is not meant to, nor does it work. I'm providing a comparison of working and theoretical code to suggest what I mean by 'direct index'.
William
댓글 수: 0
채택된 답변
James Tursa
2011년 4월 20일
No. This topic has been discussed many, many times on the newsgroup.
댓글 수: 0
추가 답변 (1개)
Sean de Wolski
2011년 4월 20일
For this specific case:
desired = x(find( x>5,2,'first'))
For the more general case (i.e. not FIND)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!