フィルターのクリア

Remove negative values of elements in a cell array

4 ビュー (過去 30 日間)
Benedict Low
Benedict Low 2017 年 9 月 6 日
コメント済み: Benedict Low 2017 年 9 月 6 日
Hi,
I have a large cell array and each element of the array has matrices of different sizes. Is there a way that I can remove negative values from the cell array, such that it only contains positive values?
I have a simple example here
a={[3,5,-1,4];[-6,7,12];[2,9,7,-4,-5,-6,8]};
How can I remove the negative numbers such that it becomes
a={[3,5,4];[7,12];[2,9,7,8]};
Thanks in advance.

採用された回答

Guillaume
Guillaume 2017 年 9 月 6 日
a = cellfun(@(v) v(v >= 0), a, 'UniformOutput', false);
Or use an explicit loop:
for idx = 1:numel(a)
a{idx} = a{idx}(a{idx} >= 0);
end
  1 件のコメント
Benedict Low
Benedict Low 2017 年 9 月 6 日
Thank you Guillaume. Perfect!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by