Find the different elements in a cell array
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi to all,
i have a problem because i have a cell array and i need to find the cells that contain both numbers 1 and 2.
Thanks.

採用された回答
Where out is your cell array:
fnh = @(v) any(v(:)==1)&&any(v(:)==2);
idx = cellfun(fnh,out)
12 件のコメント
LL
2021 年 11 月 23 日
It gave me error of invalid expression for the fnh line.
Stephen23
2021 年 11 月 23 日
@Lidia Frizzi: fixed now, please try it again.
LL
2021 年 11 月 23 日
it works thank you!!!!
Stephen23
2021 年 11 月 26 日
fnh = @(v) all(v(:)~=2);
LL
2021 年 11 月 26 日
Perfect!!!
Now i have a matrix with only 1 (when the condition is true) and 0; but if i would like to maintain in the true cells the contents of the initial cell array? how could i do this?
Stephen23
2021 年 11 月 26 日
What should the output array contain for the false indices?
LL
2021 年 11 月 26 日
Maybe 0
Stephen23
2021 年 11 月 26 日
you could replace the cells in the existing cell array:
out(~idx) = {0};
or create a new cell array:
new = num2cell(idx);
new(idx) = out(idx)
Stephen23
2021 年 11 月 29 日
@Lidia Frizzi: please show the expected result of that "merging".
LL
2021 年 11 月 29 日
So for example in the rows 6-7 and colums 8-9 i have three cells not empty the result that i would like to obtain is like this.

その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Types についてさらに検索
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

