How can use "is not equal to" command in matlab? and how terminate or cancel if else??
3 次查看(过去 30 天)
显示 更早的评论
if i want to restrict variable
length(a) "is not equal to" length(b);
length(c) "is not equal to" length(a);
then terminate
end
0 个评论
采纳的回答
James Tursa
2015-11-4
E.g.,
if( length(a) ~= length(b) || length(c) ~= length(a) )
% terminate
end
For the terminate statement, you need to be more clear. If you are terminating a loop of some sort, then
break;
If you are terminating a function with an error return, then
error('Lengths are not equal');
If termination means something else, then you need to tell us.
1 个评论
James Tursa
2015-11-4
Then use the error function as shown above. E.g.,
if( length(a) ~= length(b) || length(c) ~= length(a) )
error('Error- dimensions of array is not equal');
end
If the error is not handled by a try-catch, then this will terminate the program with an error statement.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!