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 个评论
It gave me error of invalid expression for the fnh line.
@Lidia Frizzi: fixed now, please try it again.
it works thank you!!!!
@Stephen sorry could i please ask you, how can i find all the cell without the number 2?
fnh = @(v) all(v(:)~=2);
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?
What should the output array contain for the false indices?
Maybe 0
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)
@Stephen i still need your help pls.
I have one cell array like this one, what i like to do, is to merge the contents of neighboring cells, other than zero.

@Lidia Frizzi: please show the expected result of that "merging".
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 的更多信息
另请参阅
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)
