Are there any alternatives to try/catch statements that are supported by code generation?
Mostra commenti meno recenti
I am trying to prepare an application (prepared in App Designer and connected to a Simulink model) to be packaged as a standalone executable.
My Simulink model is fairly simple: using Interpreted MATLAB function blocks as input and output to an s-function block (which is connected to a much larger and complicated external model).
In order to create a standalone executable for an application connected to a Simulink model, I found that I have to use Simulink Compiler, which does not support Interpreted MATLAB functions, so I am trying to convert their functionality to MATLAB function blocks.
As it turns out, MATLAB function blocks are further subject to code generation limitations, which exclude try/catch statements. These try/catch statements are primarily used to catch and pass error code or correct user input with instructions, which is a core functionality of deploying a proprietary application in industry.
Therefore, I was wondering if there are any alternatives to try/catch statements that are supported by code generation? I could not find any simple fix in the documentation. Are there any options besides coding in more input validation?
Thanks!
3 Commenti
dpb
il 25 Giu 2024
I don't have Simulink and what I could find in the online doc for Simulink Compiler didn't lead me to the conclusion try...catch...end isn't supported, but may you've run into it already whether it's documented where easily found or not...
But, I know for certain that an executable can be built with the Matlab compiler/AppDesigner that does include them for what (little?) that may be worth. I dunno if there would possibly be any way to use code from it with Simulink or not.
As far as substitutes, I am unawre of any other high-level coding construct that will help or that can simulate the effect; lacking the feature was what always caused building production code in Fortran to be such a pain before; the amount of diagnostic code required to be robust was always a tremendous effort.
Roop
il 25 Giu 2024
dpb
il 25 Giu 2024
Unfortunately, if you can't use try...catch construct, then ensuring the error doesn't happen first is really the only alternative because if you let any error happen, BOOM! goes the app and if's then too late to do anything; the horse has already left the barn.
About all you can do to help is probably write one or more helper functions that let you screen inputs for validity(*); the issue happens if such screening needs a lot of additional logice to be effective if you can't just select a range of valid inputs.
Of course, that also gets into how you let the user actually interact with your app, if they can type freely into a text field and you then convert to a number, the problem is much more complex than if it's a slider (which would be the way one could go for input that must be in a range to avoid/prevent the error if it is that simple).
(*) One of my generic utility functions is simply "syntactic sugar" to replace the logic construct in the top level user code with a function is
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
end
This has the advantage of being able to be combined in logic combinations without the muss of the actual comparison to try to read plus is vectorized. Things such as this customized for your specific needs can help, but it's still going to be a lot of work to make something that is very robust unless you can otherwise control the way the user interacts with the app.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Simulink Coder in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!