657
edits
m (→Solution) |
|||
Line 218: | Line 218: | ||
The next version of octave (3.6) implements the <code>CollectOutput</code> switch as seen in example 8 here: http://www.mathworks.com/help/techdoc/ref/textscan.html | The next version of octave (3.6) implements the <code>CollectOutput</code> switch as seen in example 8 here: http://www.mathworks.com/help/techdoc/ref/textscan.html | ||
===Using variable strings in commands=== | |||
For example, to plot data using a string variable as a legend: | |||
Option 1 (simplest): | |||
{{Code|Using variable strings in commands. op1|<syntaxhighlight lang="octave" style="font-size:13px"> | |||
legend = "-1;My data;"; | |||
plot(x, y, legend); | |||
</syntaxhighlight>}} | |||
Option 2 (to insert variables): | |||
{{Code|Using variable strings in commands. op2|<syntaxhighlight lang="octave" style="font-size:13px"> | |||
plot(x, y, sprintf("-1;%s;", dataName)); | |||
</syntaxhighlight>}} | |||
Option 3 (not as neat): | |||
{{Code|Using variable strings in commands. op3|<syntaxhighlight lang="octave" style="font-size:13px"> | |||
legend = 'my legend'; | |||
plot_command = ['plot(x,y,\';',legend,';\')']; | |||
eval(plot_command); | |||
</syntaxhighlight>}} | |||
These same tricks are useful for reading and writing data files with unique names, etc. |
edits