How to determine which indices in a row cell array contains the value 1, even when there are null vectors [ ] in the cell array?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
If I have a row cell array,
C = {[], [], [], [], 1, 1, 1, 1, 1, 1, 4, 4, 5, 5, 5, [], [], []}
and I would like to know where in the cell array (i.e. which column) the 1 values are located. How do I grab the indices of where 1 is located because when I use the following,
d = find([b{:}] == 1)
I get the following output.
d = [1, 2, 3, 4, 5, 6]
which is not what I want because it ignores the null vector, []...Ideally, I would like the following output, or something like that.
d = [5, 6, 7, 8, 9, 10]
I'm using MATLAB 2015a btw. Any help or advice would be appreciated. Thanks.
0 个评论
采纳的回答
更多回答(2 个)
Andrei Bobrov
2015-7-25
编辑:Andrei Bobrov
2015-7-25
C = {[], [], [], [], 1, 1, 1, 1, 1, 1, 4, 4, 5, 5, 5, [], [], []};
b = C;
b(cellfun(@isempty,b))={nan};
d = find([b{:}]==1);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!