Create a vector with the non-zero indices of a cell array
3 ビュー (過去 30 日間)
古いコメントを表示
I have a cell array. I need to create a column vector that returns the non-empty row indices.
I have tried this way but there is something to improve.
idx = find(~cellfun(@isempty,matrix),1);
% idx = [2;4]; % this is the result I need to get
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1442532/image.png)
0 件のコメント
採用された回答
Dyuman Joshi
2023 年 7 月 26 日
%Random data
y = {[],[];[] repmat({rand},3,3); [] []; repmat({rand},4,3) []}
%Find if all cells in a row are empty or not and then negating
z1 = ~all(cellfun('isempty', y),2)
idx1 = find(z1)
Another approach using any() instead of all() -
%Find if any cells in a row are not empty
z2 = any(~cellfun('isempty', y),2)
idx2 = find(z2)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
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!