0

I got the answer from the following question. It asks me to create a bash file. The question is in the title

How to call MATLAB functions from the Linux command line?

Thus I tried the following code, as given in the answer.

    b_exec=matlab
    X="localize(r,q)"
    echo ${X} > matlab_command_rq.m
    cat matlab_command_rq.m 
    ${matlab_exec} -nojvm -nodisplay -nosplash < matlab_command_rq.m
    rm matlab_command_rq.m

The original code in the answer was

    matlab_exec=matlab
    X="${1}(${2})"
    echo ${X} > matlab_command_${2}.m
    cat matlab_command_${2}.m
    ${matlab_exec} -nojvm -nodisplay -nosplash < matlab_command_${2}.m
    rm matlab_command_${2}.m

In the explanation, they mentioned that $1 was function and $2 was inputs. correspondingly, I replaced it with my function 'localize' and inputs (r,q)

But I got the following error

    localize(r,q)
    ./matlab_batcher.sh: 5: ./matlab_batcher.sh: -nojvm: not found

The echo seems to be working. But I really do not know what is happening after that. Could you please help me and tell me the right way to call the matlab function with its arguments???

I called it using the following statement

   sh ./matlab_batcher.sh localize r q

1 Answer 1

1

You need to change your b_exec back to matlab_exec, or you need to change

${matlab_exec} -nojvm ...

to

${b_exec} -nojvm ...

Either way, you need to make it consistent.

Sign up to request clarification or add additional context in comments.

13 Comments

could you please tell me wat you mean by saying I should make it consistent? And the way am calling the function, is it the correct way?
I mean that you can't name your variable b_exec and then reference matlab_exec (which is then undefined). As for how you're calling it, since you hardcoded the function name and arguments into your script, you can just do sh ./matlab_batcher.sh.
You're still getting -nojvm: not found? That seems unlikely. You should double-check your work. Failing that, post exactly what you now have.
That means matlab isn't in your search path. The easiest thing to do is just use the full path to matlab, e.g. set matlab_exec=/path/to/matlab (wherever that is on your system). If you don't know, you'll have to ask your local support over there.
Then you should go back to the original version of the code and make a call like sh ./matlab_batcher.sh localize "r,q".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.