title: In MATLAB, how to store Unix stdout in cell array for multi-line commands?
body: <p>I have to run unix code on a remote system that does not have MATLAB. I call it like this</p>
  
  <pre class="lang-matlab prettyprint-override"><code>% shared key between computers so no password required to type in
  ssh_cmd = 'ssh login@ipaddress '; 
  for x = 1:nfiles
    cmd = sprintf('calcPosition filename%d',x); 
    % as an example, basically it runs a c++ command 
    % on that computer and I pass in a different filename as an input
    full_cmd = [ssh_cmd, cmd];
    [Status,Message] = system(full_cmd);
    % the stdout is a mix of strings and numbers
    % &lt;code that parses Message and handles errors&gt;
  end
  </code></pre>
  
  <p>For a small test this takes about 30 seconds to run. If I set it so that</p>
  
  <pre class="lang-matlab prettyprint-override"><code>full_cmd = [ssh_cmd, cmd1; cmd2; cmdN]; % obviously not valid syntax here
  % do the same thing as above, but no loop
  </code></pre>
  
  <p>it takes about 5 seconds, so most of the time is spent connecting to the other system. But <code>Message</code> is the combined stdout of all n files.</p>
  
  <p>I know I can pipe the outputs to separate files, but I'd rather pass it back directly to MATLAB without addition I/O. So is there a way to get the stdout (<code>Message</code>) as a cell array (or Unix equivalent) for each separate command? Then I could just loop over the cells of <code>Message</code> and the remainder of the function would not need to be changed.</p>
  
  <p>I thought about using an identifier text around each command call as a way to help parse <code>Message</code>, e.g.</p>
  
  <pre class="lang-matlab prettyprint-override"><code>full_cmd = [ssh_cmd; 'echo "begincommand " '; cmd1; 'echo "begincommand " '; cmd2]; % etc
  </code></pre>
  
  <p>But there must be something more elegant than that. Any tips?</p>