Save vector to m-file

27 views (last 30 days)
Tomas
Tomas on 2 Oct 2014
Commented: Oleg Komarov on 3 Oct 2014
Hi. I have a task where I am to create a file called bestPath.m which in turn should include a vector called bestPath. I have searched the net, but no luck. Thanks in advance.
  2 Comments
Tomas
Tomas on 2 Oct 2014
Yes, that is the intent. It's a task I've gotten from school :).

Sign in to comment.

Answers (1)

Oleg Komarov
Oleg Komarov on 2 Oct 2014
Edited: Oleg Komarov on 2 Oct 2014
Since R2014a you can use matlab.io.saveVariablesToScript():
a = rand(10);
matlab.io.saveVariablesToScript('test.m','a')
Check the content of the .m file with
edit test
Calling test from the command line will evaluate a into the workspace.
  2 Comments
Oleg Komarov
Oleg Komarov on 3 Oct 2014
If my answer solves your problem, please accept it.

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!