finding index to a vector in structure
1 次查看(过去 30 天)
显示 更早的评论
Consider the following example:
f = struct
f(1).x = 5;
f(2).x = 1:10;
f(3).x = 1;
f(4).x = 2;
I wish to find an automated way of finding which element of the field x is a vector. In the example above, the answer is element 2. Thank you!
0 个评论
采纳的回答
the cyclist
2015-10-1
I could not figure out a vectorize way to do this, but perhaps this loop is good enough:
n = size(f,2);
isVectorF = false(1,n);
for nv = 1:n,
isVectorF(nv) = not(isscalar(f(nv).x));
end
isVectorF is a logical with 0 = scalar and 1 = vector.
1 个评论
Jos (10584)
2015-10-1
isVectorF = arrayfun(@(k) isvector(f(k).x) && numel(f(k).x)>1 ,1:numel(f))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!