How can I determine if elements in an array are equal to a scalar

7 次查看(过去 30 天)
I have an array like the following
a = {[1] [3] ['A'];[3] [1,2] []};
and I want to check to see if each element of the array is equal to 3 or something, so I would want an output like this:
Output = [0,1,0;1,0,0];
This seems like something that should be easy to do but I can't figure it out. I tried doing
Output = cellfun(@eq,a,3)
But that doesn't seem to work.

采纳的回答

James Tursa
James Tursa 2015-7-6
Output = cellfun(@(x)isequal(x,3),a);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by