Can I assign a single value to multiple elements of a cell array without a loop
古いコメントを表示
For example, I have an array that looks like
myArray =
[3] [] [3] []
I'd like to fill out the empty elements of myArray with zeros, but, obviously, the following doesn't work:
myArray{find(cellfun(@isempty,myArray))} = 0
Obviously, I could write a loop, but there has to be a better way!
Thanks for any suggestions!
採用された回答
その他の回答 (1 件)
Guillaume
2015 年 2 月 17 日
Your main problem is the confusion between () and {}. Secondly, use logical indexing, rather than find:
myArray(cellfun(@isempty, myArray)) = {0};
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!