Effacer les filtres
Effacer les filtres

Prevent mlint warning for onCleanup like return value

35 vues (au cours des 30 derniers jours)
tommsch
tommsch le 2 Juil 2024 à 7:07
Commenté : tommsch le 2 Juil 2024 à 9:35
I wrote a function, similar to onCleanup. I noticed that Matlab does not give a mlint warning for the following code.
dummy = onCleanup( @() some_func );
But for my own function
dummy = MyOwnCleanup( @() some_func );
I get the warning Value assigned to variable might be unused, which I need to silence with %#ok<NASGU>. Obviously, Matlab recognizes the onCleanup call and does not emit a warning. How can I acchieve similar behaviour for my own MyOwnCleanup function?
  2 commentaires
Rik
Rik le 2 Juil 2024 à 9:13
This is probably not possible without major interference with the editor. It will probably be an ugly hack.
A much easier hack is to overload the built-in onCleanup function. I don't think I would recommend this.
What exactly is your version doing? I might be interested in using it myself.
tommsch
tommsch le 2 Juil 2024 à 9:35
For the original onCleanup function I do not like that it is often a little verbose. E.g. to change the working directory back you have to do
olddir = pwd;
cleandir = onCleanup( @() cd(olddir) );
So I wrote a cleanup function which accepts parameters, so you can write
cleandir = onCleanup_lazy( @(x) cd( x ), pwd );

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Error Handling dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by