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!