필터 지우기
필터 지우기

Convertion between empty matrix and Null

조회 수: 1 (최근 30일)
Sean Danaher
Sean Danaher 2012년 3월 9일
댓글: Langyu 2013년 11월 2일
I am trying to check if two vectors are identical, quite often these can be null or empty and of different lengths. I confess my ignorance as to the processes which decide wheather the matrix is null or empty, but I am trying to use an all command (the vectors are sorted and have unique elements). I hit a bug when one vector is null and the other Empty. Any ideas?
{strato =
[]
>> stratn
stratn =
Empty matrix: 1-by-0
>> stratn==stratn
ans =
Empty matrix: 1-by-0
K>> all(stratn==stratn)
ans =
1
K>> all(strato==strato)
ans =
1
K>> all(strato==stratn) ??? Error using ==> eq Matrix dimensions must agree.}

채택된 답변

James Tursa
James Tursa 2012년 3월 9일
Why not use the isequal function?

추가 답변 (3개)

Jacob Halbrooks
Jacob Halbrooks 2012년 3월 9일
It is informative to inspect the dimensions of []:
>> size([])
ans =
0 0
In equality checks, the dimensions must agree, so this will be unequal to "vector" empties:
>> isequal(ones(0,0), ones(0,1))
ans =
0
I would suggest you use ISEMPTY if you want to treat all empties as the same:
>> isequal(isempty(ones(0,0)), isempty(ones(0,1)))
ans =
1

Walter Roberson
Walter Roberson 2012년 3월 9일
A matrix is empty if any of its dimensions are 0.
See also isempty()
  댓글 수: 1
Langyu
Langyu 2013년 11월 2일
Thanks, I think this answer works best.

댓글을 달려면 로그인하십시오.


Sean Danaher
Sean Danaher 2012년 3월 12일
many thanks to James and also Jacob with a more comprehensive answer

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by