Effacer les filtres
Effacer les filtres

isempty function does not work for me

9 vues (au cours des 30 derniers jours)
NeGM
NeGM le 9 Avr 2021
Commenté : Stephen23 le 9 Avr 2021
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 commentaires
NeGM
NeGM le 9 Avr 2021
Thank you, you are right!
Stephen23
Stephen23 le 9 Avr 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:

Connectez-vous pour commenter.

Réponse acceptée

Chendi Lin
Chendi Lin le 9 Avr 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 commentaire
Steven Lord
Steven Lord le 9 Avr 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by