How can I fix this error - "Matrix dimensions must agree" "x{end,1}.AppName == aa1{selA,1}.Type"
조회 수: 1 (최근 30일)
이전 댓글 표시
if Sign == 1
if appm==0
tt.AppName=aa1{selA,1}.Type;
tt.status='[On]';
tt.dataOn=i-7;
x{end+1,1}=tt;
clear tt;
appm=1;
end
SignStr = '[On]';
iCount = iCount + 1;
if ~isempty(r{selA,1})
r{selA,1} = r{selA,1} + 1;
else
r{selA,1} = 1;
end
else
if isempty(x)~=1 && x{end,1}.AppName == aa1{selA,1}.Type
% AppName=aa1{selA,1}.Type;
tt.AppName=aa1{selA,1}.Type;
tt.status='[Off]';
tt.dataOn=i-7;
x{end+1,1}=tt;
clear tt;
end
댓글 수: 1
Guillaume
2018년 12월 24일
Please use proper indenting in your code as it makes it much more readable.
Comments are missing from your code.
답변 (2개)
Image Analyst
2018년 12월 24일
Evidently selA is not a single scalar number so you're not selecting a single cell, but an array of cells.
댓글 수: 2
Image Analyst
2018년 12월 24일
Well, just a guess since we can't debug it. But here is a solution guaranteed to solve it: Click here
It also helps to break things into simple, temporary variables:
v1 = x{end,1}.AppName
v2 = aa1{selA,1}.Type
theyMatch = v1 == v2
My current guess is that they are strings and he should be using strcmpi(v1, v2) instead of using ==.
theyMatch = strcmpi(v1, v2);
if theyMatch && ............
Guillaume
2018년 12월 24일
편집: Guillaume
2018년 12월 24일
x{end,1}.AppName and aa1{selA,1}.Type are not the same size and neither of them is scalar in the non-scalar dimension of the other. As the error message tells you "Matrix dimensions must agree" since == does an element by element comparison.
if ~isempty(x) && strcmp(x{end,1}.AppName), aa1{selA,1}.Type) %return true if both char vectors are the same
Otherwise, it may be that isequal may work, or it may be that you've got a bug somewhere that makes the two matrices a different size.
Note that:
if isempty(x)~=1
is simpler as
if ~isempty(x)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!