How to stop the program if an array is empty?
1 次查看(过去 30 天)
显示 更早的评论
signal1 = [1,2,3,4,5,6];
signal2 = [7,8,9,10,11,12];
signal3 = [13,14,15,16,17,18];
signal4 = [19,20,21,22,23,24];
signal5 = [25,26,27,28,29,30];
signal6 = [31,32,33,34,35,36];
bufferSize = 6;
buffer = nan(bufferSize,6);
init = 1;
for i = 1:bufferSize
empty = sum(isnan(buffer(i,:))); %check status of each row
if empty == 6
buffer(i,1) = signal1(init);
buffer(i,2) = signal2(init);
buffer(i,3) = signal3(init);
buffer(i,4) = signal4(init);
buffer(i,5) = signal5(init);
buffer(i,6) = signal6(init);
init = init + 1; %infite number of data as input
try
signal1(1,init);
catch
msgbox(['Insufficient data at position ',num2str(init)])
break;
end
end
end
I want to implement something similar to try and catch but in Simullink. How can I do this? I tried the same method in Simulink, but it looks that try and catch is not used in Simulink.
0 个评论
回答(1 个)
Raunak Gupta
2020-2-19
Hi,
As per understanding from the question you want to stop the simulation and through an error whenever certain array is empty.
One way to do it is checking the size of array using size. With the help of MATLAB Function Block you can take the array in question as input and return its size as output. That output will then be passed to the Assertion Block which will stop the simulation and through an error whenever the size of array is zero in any dimension. You may also give MATLAB expression to be evaluated when the assertion fails in the block properties of Assertion Block. All of this will be CodeGen supported.
For other test model components, you may refer to the following:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!