Question

In the bash script, it is possible to do following:

    cat > my.txt << EOF
         bla-bla-bla
         bla-bla-bla
         bla-bla-bla
    EOF

Is there any way I could execute this command inside a matlab m-file? I am thinking about system, but it seems it accept only simple one-string system commands.

Was it helpful?

Solution

You can create a system command that contains linebreaks with sprintf:

system_command = sprintf('cat > my.txt << EOF\n');
system_command = sprintf('%s\nbla-bla-bla', system_command);
system_command = sprintf('%s\nbliblablub', system_command);
system_command = sprintf('%s\nEOF', system_command);
system(system_command);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top