フィルターのクリア

Matlab delete values

3 ビュー (過去 30 日間)
athpapa -
athpapa - 2011 年 3 月 8 日
Hello,
I have a table: A=[2 5 5 0] and I use this function to sort it in descend order: [C, Index] = sort(A) and the result: C=[5 5 2 0]. Then I use this: t=A(Index(1)); A(A==t)=[]; to find and delete the value of table A which match the first value of table C. But when I have same values as in my example (5, 5) it deletes them both. I want to delete only one value each time. I mean I want A=[2 5 0] and so C become: C=[5 2 0]. What is the right function? I want this function to work for random arrays and not only for the example!
Thank you..
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 3 月 8 日
Note: to sort in descending order, you need
[C, Index] = sort(A,'descend');

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

採用された回答

Matt Tearle
Matt Tearle 2011 年 3 月 8 日
Much as I love logical indexing, here's a case for using find with the number and 'first' or 'last' option:
idx = find(A==t,1,'first');
A(idx) = [];
That said, it seems like you're trying to remove the maximum (or minimum) value, but only one. In which case, why not simplify a bit:
idx = find(A==max(A),1,'first');
A(idx) = [];
Or even just use the fact that max will return a single index for the maximum value:
[~,idx] = max(A);
A(idx) = [];
  1 件のコメント
athpapa -
athpapa - 2011 年 3 月 8 日
thank you!!

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

その他の回答 (1 件)

Matt Fig
Matt Fig 2011 年 3 月 8 日
A(find(A==T,1,'first')) = [];
Or, you could just use Index directly:
A(Index(1)) = []
And avoid the call to FIND and/or any comparisons.
  1 件のコメント
athpapa -
athpapa - 2011 年 3 月 8 日
thank you!!

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by