Effacer les filtres
Effacer les filtres

How do I pass the correct string for a function input parameter?

11 vues (au cours des 30 derniers jours)
cui,xingxing
cui,xingxing le 11 Avr 2023
Commenté : Ryan Livingston le 12 Avr 2023
For example, I want to debug a mex file using valgrind in a linux terminal and need to pass in a string using the following command, how should I properly ensure that the function input parameters are of the string type?
I.e. how do I nest string double quotes within a string in matlab function imput arguments?
Using Valgrind
matlab -nojvm -nosplash -r "myMexMatlabFunc(myParams)" -D"valgrind --tool=memcheck --leak-check=yes --log-file=valMatlabLog"
note: myParams is string type params.
I tried adding the following double quotes to the input parameters but it didn't work.
matlab -nojvm -nosplash -r "myMexMatlabFunc(""./imageViewSt.yml"")" -D"valgrind --tool=memcheck --leak-check=yes --log-file=valMatlabLog2"
myMexMatlabFunc(./imageViewSt.yml)
|
Invalid use of operator.
  4 commentaires
Ran Yang
Ran Yang le 11 Avr 2023
Oh, that's a Linux terminal problem. Try using \".
-r "myMexMatlabFunc(\"./imageViewSt.yml\")"
cui,xingxing
cui,xingxing le 11 Avr 2023
Thank you for your answer, it works! Please revise your question slightly so that I can accept the answer

Connectez-vous pour commenter.

Réponse acceptée

Ran Yang
Ran Yang le 11 Avr 2023
Modifié(e) : Ran Yang le 11 Avr 2023
In a Linux terminal, you can use a backslash (\) within quotes to escape formatting, which allows you to put quotes within quotes.
-r "myMexMatlabFunc(\"./imageViewSt.yml\")"
will be interpreted as:
-r "myMexMatlabFunc("./imageViewSt.yml")"
and allows you to pass strings into Matlab this way.
  3 commentaires
cui,xingxing
cui,xingxing le 11 Avr 2023
matlab -nojvm -nosplash -r "disp(\"hello world\")"
now it works! thanks very much!
Ryan Livingston
Ryan Livingston le 12 Avr 2023
To make this simpler to think about, I put anything non-trivial in a script or function and then just call that with -r myFunctionOrScript or -batch myFunctionOrScript. That helps you avoid the need to deal with shell quote escaping and the like.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Argument Definitions dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by