MATLAB中的特殊比较
嗨,我正努力做到这一点:MATLAB中的特殊比较,matlab,Matlab,嗨,我正努力做到这一点: for i=1:maxaps for j=1:length(num2) **if (isequal(sortedCell(i),txt2(j)) && sortedCell(i)~=0)** %important line rssi2sorted(i)=rssi2(j); %I don't think we need matching part break; end
for i=1:maxaps
for j=1:length(num2)
**if (isequal(sortedCell(i),txt2(j)) && sortedCell(i)~=0)** %important line
rssi2sorted(i)=rssi2(j); %I don't think we need matching part
break;
end
end
end
我收到这个错误:
??? Undefined function or method 'ne'
for input arguments of type 'cell'.
Error in ==> sortingmethod at 116
if
(isequal(sortedCell(i),txt2(j))
&& sortedCell(i)~=0)
如果我这样尝试:
for i=1:maxaps
for j=1:length(num2)
**if (isequal(sortedCell{i},txt2(j)) && sortedCell(i)~=0)** %important line
rssi2sorted(i)=rssi2(j); %I don't think we need matching part
break;
end
end
end
for j=1:length(num2)
c = strcmp(sortedCell,txt2(j));
if any(c)
rssi2sorted(c)=rssi2(j);
break;
end
end
由于格式原因,无法比较元素:
>> sortedCell{1}
ans =
00:1e:58:f4:15:f7
>> txt2(6)
ans =
'00:1e:58:f4:15:f7'
有没有关于如何解决这个问题的建议
谢谢 我认为问题实际上在于这一部分(您的错误所指的部分): 您将单元格(而不是其内容)与零进行比较。你应使用:
sortedCell{i}~=0
编辑: 如果问题不是关于错误消息,而是关于如何比较字符串,只需使用(不要使用
=
、eq
或isequal
来比较字符串):
我不知道您添加的&&sortedCell{I}~=0
部分用于什么,但是如果需要,您可以将其添加回去
strcmp
还可以将单元数组作为输入(请参阅文档),这样您就可以摆脱for
循环。我不知道你的代码是做什么的,但也许你可以用这样的东西:
for i=1:maxaps
for j=1:length(num2)
**if (isequal(sortedCell{i},txt2(j)) && sortedCell(i)~=0)** %important line
rssi2sorted(i)=rssi2(j); %I don't think we need matching part
break;
end
end
end
for j=1:length(num2)
c = strcmp(sortedCell,txt2(j));
if any(c)
rssi2sorted(c)=rssi2(j);
break;
end
end
使用strcmp(strcmpi忽略的情况)测试字符串是否相同,如果值在数字上相等,则使用isequal进行测试。e、 g
if ( strcmp(sortedCell{i},txt2(j)) && sortedCell(i)~=0 )
谢谢你的回答。请仔细考虑这个问题。我已经做了你提到的事情,但没有起作用(问题的结尾)你是否在尝试:
~isempty(sortedCell(I))
当你写sortedCell(I)~=0
时?