フィルターのクリア

index returned array directly

8 ビュー (過去 30 日間)
William
William 2011 年 4 月 20 日
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

採用された回答

James Tursa
James Tursa 2011 年 4 月 20 日
No. This topic has been discussed many, many times on the newsgroup.

その他の回答 (1 件)

Sean de Wolski
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)
  1 件のコメント
William
William 2011 年 4 月 20 日
Sean de is correct for the case given but I should have been more clear. I am looking for the general case, I arbitrarily chose find as an example of when this might be useful.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by