0

我不知道如何使用isempty函数,例如:

模拟的第一个矩阵是

[18 1 0 0 0;12 0 0 0 1;15 1 1 0 0]

模拟的第二个矩阵是

[25 0 0 0 0;30 1 1 0 0;14 0 0 1 0]

模拟的第三个矩阵是

[50 1 0 0 0;12 0 0 1 0;24 1 1 1 0] 

我使用了以下功能:

idxfun=@(x)find(ismember(x(:,2:end),[1 0 0 0],'rows'))

a=the first matrix(idxfun(the first matrix),:) 

答案如下:18 1 0 0 0第二个矩阵答案是: empty matrix:0-by-5那么模拟停止!我想要的是让模拟继续并转到下一个矩阵,在这个例子中答案将是50 1 0 0 0

4

2 回答 2

1

只需通过isempty函数发送结果:

temp = [25 0 0 0 0;30 1 1 0 0;14 0 0 1 0];
h = idxfun(temp);
if (isempty(h))
    disp('Pattern not found');
else
    disp('Pattern found');
end

temp = [12 0 0 1 0;50 1 0 0 0;24 1 1 1 0];
h = idxfun(temp);
if (isempty(h))
    disp('Pattern not found');
else
    disp('Pattern found');
end
于 2013-02-05T03:52:59.073 回答
-1

您可以使用trycatch

 try
    a = result( idxfun( result ), : );
 catch em
    a = [];
    fprintf(1, 'no match found\n');
 end
于 2013-02-05T07:30:55.497 回答