Finding structure array entries with certain values
278 次查看(过去 30 天)
显示 更早的评论
Hello,
What is the way to find all structure array entries with specific values?
E.g. I tried:
find(cell_data.CN == 4)
But that returns:
Error using ==
Too many input arguments.
Kind regards,
Tom
0 个评论
采纳的回答
Jos (10584)
2014-3-7
I assume that celldata is a structure array
% create some example data
for k=1:10, celldata(k).CN = ceil(4*rand) ; end
% method 1: easy
allCN = [celldata.CN] % comma separated list expansion
tf1 = allCN == 4
index1 = find(tf1)
% method 2: very flexible
fun = @(x) celldata(x).CN == 4 % useful for complicated fields
tf2 = arrayfun(fun, 1:numel(celldata))
index2 = find(tf2)
Both methods can be written as one-liners.
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!