1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

空の配列と空のセル配列を合わせたら空じゃなくなる件

Last updated at Posted at 2019-02-21

empty + empty = notempty

matlabには空かどうか判定するisemptyがあります。
ここに空の配列を入れてみると、1(=true)が返ってきます。そらそうですね。

array.m
>> isempty([])
     ans=
       logical
         1

じゃあ空のセル配列では?
もちろん1が返ってきます。想像通りですね。

cell_array.m
>> isempty({})
     ans=
       logical
         1

じゃあこの二つを合わせて、空のセル配列に空の配列を入れてみるとどうなるか。
答えは0(=false)になります。
配列は空ですが、セル配列は空の配列が入っている状態なので0です。

multi_array.m
>> isempty({[]})
     ans=
       logical
         0

空がどういう意味かちゃーんと考えておかないと思わぬところでハマるのでお気をつけくださいませ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?