[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## How to write function to plot?

**From**: |
John B. Thoo |

**Subject**: |
How to write function to plot? |

**Date**: |
Sat, 25 Apr 2009 07:52:04 -0700 |

`Hi, everyone. I have a question about writing a function for
``plotting some data saved to a file.
`

`I have some data saved to a file "heat_q.mat" for the variables k, x,
``t, u. Here's a snippet.
`
%%%%%%%%%% begin snippet %%%%%%%%%%%

`# Created by Octave 3.0.5, Fri Apr 24 13:11:38 2009 PDT <address@hidden
``Thoos-Computer.local>
`# name: k
# type: scalar
3
# name: x
# type: matrix
# rows: 1
# columns: 21

` 0 0.3141592653589793 0.6283185307179586 0.9424777960769379
``1.256637061435917
`...
# name: t
# type: range
# base, limit, increment
0 1 0.1
# name: u
# type: matrix
# rows: 21
# columns: 11
0 0 0 0 0 0 0 0 0 0 0

` 0.8090169943749475 0.3323236694342593 0.136510137653631
``0.05607490346365374
`...
%%%%%%%%%% end snippet %%%%%%%%%%%
If I load the file and then enter on the command line
> l = 3;
> plot (x, u(:,l), '-ok', x, exp (-k^2*t(l))*sin (k*x), '-b');
then I get a plot. However, if I use the following function
%%%%%%%%%%%%%%%%%%%%%%%
function plotheat_q (l)
% plot numerical solution and exact solution at time t0+l*dt;
plot (x, u(:,l), '-ok', x, exp (-k^2*t(l))*sin (k*x), '-b');
endfunction
%%%%%%%%%%%%%%%%%%%%%%%
then I get the following error:
octave-3.0.5:2> load heat_q.mat k x t u
octave-3.0.5:3> plotheat_q (3)
error: `x' undefined near line 4 column 7
error: evaluating argument list element number 1

`error: called from `plotheat_q' in file `/Users/jbthoo/Desktop/
``NumMethPractice/plotheat_q.m'
`octave-3.0.5:3>
What am I doing wrongly?
Thanks.
---John.

**How to write function to plot?**,
*John B. Thoo* **<=**