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

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

Use char to specify your file instead.
-r "myMexMatlabFunc('./imageViewSt.yml')"
@Ran Yang But I still want my input function parameters to be explicitly double-quoted rather than single-quoted
Oh, that's a Linux terminal problem. Try using \".
-r "myMexMatlabFunc(\"./imageViewSt.yml\")"
Thank you for your answer, it works! Please revise your question slightly so that I can accept the answer

댓글을 달려면 로그인하십시오.

 채택된 답변

Ran Yang
Ran Yang 2023년 4월 11일
편집: Ran Yang 2023년 4월 11일
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

Thanks for your reply, but the situation I encountered above did not work, adding "myMexMatlabFunc(""./imageViewSt.yml"")" as an input parameter ended up being interpreted as not having any double quotes?
myMexMatlabFunc(./imageViewSt.yml)
------------A minimalist Case-----------
matlab -nojvm -nosplash -r "disp(""hello world"")"
disp(hello world)
|
Invalid expression. Check for missing multiplication operator, missing or
unbalanced delimiters, or other syntax error. To construct matrices, use
brackets instead of parentheses.
matlab -nojvm -nosplash -r "disp(\"hello world\")"
now it works! thanks very much!
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2023a

질문:

2023년 4월 11일

댓글:

2023년 4월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by