How to use try/catch from the MATLAB engine API

5 vues (au cours des 30 derniers jours)
Brandon Barker
Brandon Barker le 28 Mai 2020
I'm trying to design a generic function from the MATLAB C Engine API that allows executing statements in a try/catch, and returning a wrapped result (wrapped differently depending on if the result is an error or success).
As I understand it, engEvalString can only execute a single statement (mabye I'm wrong). If this is the case, since try/catch is inherrently multi-line in MATLAB, I'm not sure how to achieve the desired result.
Ultimately I'd like to have code that matches the following pseudo-code:
engEvalStringSafe(eng, statementString) =
tryStmt = """
try
struct('success', statementString);
catch ex
struct('failure', ex)
end"""
engEvalString(eng, tryStmt)

Réponses (0)

Catégories

En savoir plus sur Call MATLAB from C dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by