سؤال

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.

هل كانت مفيدة؟

المحلول

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top