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
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
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
Guillaume
Guillaume 2018년 12월 24일
편집: Guillaume 2018년 12월 24일
Hum, no. If SelA wasn't scalar the error would be Expected one output from a curly brace or dot indexing expression, but there were xxx results.
aa1{selA,1}.Type would error even before matlab can carry out the comparison.
Image Analyst
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
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 you are comparing char vectors, the function to use is strcmp:
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)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by