isempty function does not work for me
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
Since "out1" is empty shouldnt the logical output be 1 and not 0? any help is greatly appreciated. Thank you
2 Commenti
Stephen23
il 9 Apr 2021
"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:
Risposta accettata
Chendi Lin
il 9 Apr 2021
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 Commento
Steven Lord
il 9 Apr 2021
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.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!