Je ne suis pas sûr de répondre exactement à ta question mais voici un exemple très simple.
Le code suivant :
ne fonctionne pas est renvoie le message :
??? Attempted to access (-2); index must be a positive integer or logical.
=> voir la : Subscript indices must either be real positive integers or logicals.
On peut donc trouver une alternative comme ceci :
1 2 3 4 5 6 7 8 9 10
| i=-2;
while 1
try
X(i) = rand;
break
catch
i=i+1;
end
end |
Ce code (très théorique) fonctionne.
Pour voir ce qui se passe exactement, il suffit de modifier un peu le CATCH comme ceci :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
i=-2;
while 1
try
X(i) = rand;
break
catch ME
disp(ME.message)
i=i+1;
end
end
X |
Ce qui retourne :
1 2 3 4 5 6 7 8
|
Attempted to access (-2); index must be a positive integer or logical.
Attempted to access (-1); index must be a positive integer or logical.
Attempted to access (0); index must be a positive integer or logical.
X =
0.6557 |
Les erreurs sont donc bien retournées, mais le programme ne s'arrête pas pour autant.
Partager