How to stop the program if an array is empty?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Raunak Gupta
el 19 de Feb. de 2020
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 comentarios
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!