Cookbook: Difference between revisions

208 bytes added ,  21 September 2012
Line 195: Line 195:


If the variable Text is a cell array of strings (of length <15) with two columns and a certain number of rows, simply type for the kth row of Text
If the variable Text is a cell array of strings (of length <15) with two columns and a certain number of rows, simply type for the kth row of Text
{{Code||<syntaxhighlight lang="octave" style="font-size:13px">
  fprintf('%15.15s | %15.15s\n', Text{k,1}, Text{k,2});
  fprintf('%15.15s | %15.15s\n', Text{k,1}, Text{k,2});
</syntaxhighlight>}}
The syntax '%<n>.<m>s' allocates '<n>' places to write chars and display the '<m>' first characters of the string to display.
The syntax '%<n>.<m>s' allocates '<n>' places to write chars and display the '<m>' first characters of the string to display.


Example:
Example:
{{Code|Example create a text table with fprintf|<syntaxhighlight lang="octave" style="font-size:13px">
  octave:1> Text={'Hello','World'};
  octave:1> Text={'Hello','World'};
  octave:2> fprintf('%15.15s | %15.15s\n', Text{1,1}, Text{1,2})
  octave:2> fprintf('%15.15s | %15.15s\n', Text{1,1}, Text{1,2})
           Hello |          World
           Hello |          World
</syntaxhighlight>}}


===Load comma separated values (*.csv) files===
===Load comma separated values (*.csv) files===
657

edits