setdiff error in some cases
이전 댓글 표시
Hi I am using setdiff in my code and i am getting 'Improper assignment with rectangular empty matrix' error in a particular case , why and how to solve this? my code is as below:
A = dataset();
A.Location = {'south'};
A.Number = 3;
B= dataset();
B.Location = {'north'};
B.Number = 3;
diff1 = setdiff(A, B); %THIS EXECUTES JUST FINE
C= dataset();
C.Location = {'north'};
C.Number = 3;
C(1, :) = [];
D= dataset();
D.Location = {'west'};
D.Number = 5;
D.Location(2, 1) = {'north'};
diff2 = setdiff(C, D); %THIS EXECUTES JUST FINE
diff3 = setdiff(C, B); %THIS GIVES ME ERROR MENTIONED ABOVE, WHY?
댓글 수: 5
This would be a great opportunity to use MATLAB's inbuilt debugging tools Set a breakpoint on/before the line that causes the error, and use the debugger workspace to investigate the variables (sizes, values, etc).
per isakson
2014년 9월 26일
What is the intention of
C(1, :) = [];
dpb
2014년 9월 26일
I'm not terribly surprised setdiff fails with an empty set as one of the inputs; the specific failure seems to be related to there being more than one element in the non-empty set given the case that succeeds.
Looks to me like one should special-case the code using the operation if it's necessary to have the case.
Always in a case such as this, ultimate response is TMW's interpretation of what their internal definition of accepted behavior should be so submit a support request at www.mathworks.com since it isn't documented.
Neesha
2014년 10월 1일
dpb
2014년 10월 1일
...What is TMW?...
The Mathworks, vendors of Matlab. Shorthand for the suggestion you contact official support at www.mathworks.com with a support request for an official interpretation of the behavior observed if you think it's important that the null input case not fail.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!