Filter löschen
Filter löschen

isempty function does not work for me

9 Ansichten (letzte 30 Tage)
NeGM
NeGM am 9 Apr. 2021
Kommentiert: Stephen23 am 9 Apr. 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 Kommentare
NeGM
NeGM am 9 Apr. 2021
Thank you, you are right!
Stephen23
Stephen23 am 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:

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Chendi Lin
Chendi Lin am 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 Kommentar
Steven Lord
Steven Lord am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by