Have a function that can take either string text or numeric input depending on what user is requesting

4 visualizaciones (últimos 30 días)
For reference here is a link that will help with the understanding of my question, So I want to know how to get my code to take in either string text or numeric values and depending if its either one it gives out its corresponding results.
Explanation:
I would also like the code to consider looking for the rest of the carmodels parameters. If instead of carmodel as input I ask for a car with this mileage and horsepower and color, return me it's corresponding battery. All within the same function, is that possible and does this even make sense? Thanks !
  2 comentarios
dpb
dpb el 19 de Mayo de 2022
You simply define the user interface and code the function as you want -- if it's just a single variable/array, it can be as simple as
function myresult=myfunction(userinput)
if isnumeric(userinput)
...
else
...
end
end
It's all your decision -- how much to try to cram into one function is part of design and factorization -- in general a function should be concise and precise -- do one thing and do it well. The top-level function my rely on many helper functions to achieve its goals but still should be pretty single-minded in its purpose and results. Truly amorphous blobs are very difficult to use/document/develop and even harder to maintain/debug.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by