Find index of first empty cell in an array row
Show older comments
I have a cell with strings and matrices. I want to add data after the last cell with data in a row.
A = {['apple'] [3x2 double] ; ['banana'] []}
For example, I want to add a matrix after the 3x2 matrix in first row, or after the 'banana' in second row.
I tried using:
find(cellfun(@isempty,A{1,:}),1)
But I get the error:
Error using cellfun
Input #3 expected to be a cell array, was double instead.
1 Comment
The syntax A{1,:} places the contents of the cell array into a comma separated list, so what you wrote is equivalent to writing this:
cellfun(@isempty,'apple','banana',[3x2 double],[])
and none of those inputs are cell arrays. See also:
Accepted Answer
More Answers (1)
A = {'apple', rand(2, 3); 'banana', []};
find(cellfun('isempty', A),1)
Note: Using the cellfun method 'isempty' is faster that providing a function handles @isempty.
There is no need to enclose a CHAR in square brackets. This wastes time only.
1 Comment
Peeyush Awasthi
on 1 Dec 2020
Hi Jan, Thanks that was the best answer even using unique.
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!