isempty function does not work for me
11 次查看(过去 30 天)
显示 更早的评论
hi everyone,
I have the following code
L{1} = L1{1};
L{2} = L2{1};
[U, P, L1SBD, L2SBD] = abu_sbd(L);
L11 = L1SBD;
L22 = L2SBD;
bw1 = logical(L11); % Obtaing 1st L1 SBD
CC1 = bwconncomp(bw1, 4); %4 connectivity, No diagonals
S1 = regionprops(CC1,'SubarrayIdx');
Blocks_1 = arrayfun(@(s)L1SBD(s.SubarrayIdx{:}), S1, 'uniform', 0);
[s1,d1] = cellfun(@size,Blocks_1);
out1 = [s1,d1];
I am applying a simultanoues block diagonalization and need to determine whether my "out1" vector is empty or not. Sometimes I get an emtpy array and Sometimes I do not, However, when I use the "isempty" function it tells me that it's not empty even when it is.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/578682/image.png)
Since "out1" is empty shouldnt the logical output be 1 and not 0? any help is greatly appreciated. Thank you
2 个评论
Stephen23
2021-4-9
"However, when I use the "isempty" function it tells me that it's not empty even when it is."
No, you are confusing function syntax (which is what you should be using) with command syntax (which treats all trailing arguments as literal strings. Your code is exactly equivalent to:
isempty('out1')
where that 1x4 character vector is clearly not empty. The difference is well documented:
采纳的回答
Chendi Lin
2021-4-9
Hi Nelson,
I believe the correct way to use "isempty" is to call "isempty(out1)". Here is the sample code:
>> a = zeros(0,2)
a =
0x2 empty double matrix
>> isempty(a)
ans =
logical
1
Best,
CD
1 个评论
Steven Lord
2021-4-9
That is correct.
isempty x
is equivalent to
isempty('x')
not
isempty(x)
The char vector 'x' is not empty. The variable x may or may not be empty.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!