0

I have checked the documents on Mathworks about command

system 

I still do not fully grasp the idea of this command. It seems that this command is designed for call external programms, such Excel, Word, R, etc.

Is there any other purposes of using this command? If I do not grasp its essential idea yet.

2 Answers 2

3
system 

is used for executing OS commands

to call Excel, Word, etc you may be better off using f.e.

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

Comments

2

In general you seem to have grasped the command in its entirety, it provides the facility to call external commands of all sorts, including operating system commands and other applications on the same (or indeed, different) computers. I suggest that you learn more about it by using it and waste no more time reading answers like this one on SO.

When you have more specific and more detailed questions, ask them.

EDIT in response to comment

Yes, you certainly can run an R program using the system command. For example, if you have a program called myRprogram.exe and if your path is set properly the Matlab command

system('myRprogram.exe') 

should run your R program.

If what you mean is 'can I run an R program which I write in Matlab and send to the R run-time system at run-time' then the answer is (probably, I'm not an R expert) yes too. You should be able to write something like:

system('R set.seed(1); num=50; w = rnorm(num+1,0,1)')

So, if you can type and execute an R program from the command line, you can build and execute it inside a Matlab program.

NOTE: I am not an R programmer, and I make no claim that the string inside the call to system is a valid way to run R at the command line. If anyone reading this knows better, please feel free to edit or to write a better answer.

3 Comments

Is it possible to write a R programme in side the 'system' command and run it in MATLAB?
@WeijieChen At least in Linux, yes. system('my-program-to-generate-R-program; Rscript my-R-program.R');. But of course you can do this also with two separate system calls in both Linux and Windows: system('my-program-to-generate-R-program'); system('Rscript my-R-program.R'); . In Linux there's also unix command.
You can also call R from within MATLAB via COM/actxserver.

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.