Editing Tips and tricks
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 132: | Line 132: | ||
==General== | ==General== | ||
===Using Variable Strings in Octave Commands=== | |||
For example, to plot data using a string variable as a legend: | |||
Option 1 (simplest): | |||
legend = "-1;My data;"; | |||
plot(x, y, legend); | |||
Option 2 (to insert variables): | |||
plot(x, y, sprintf("-1;%s;", dataName)); | |||
Option 3 (not as neat): | |||
legend = 'my legend'; | |||
plot_command = ['plot(x,y,\';',legend,';\')']; | |||
eval(plot_command); | |||
These same tricks are useful for reading and writing data files with unique names, etc. | |||
===Vectorizing Tricks=== | ===Vectorizing Tricks=== |