help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New to Octave...


From: Ben Sapp
Subject: Re: New to Octave...
Date: Mon, 14 Aug 2000 16:21:49 -0600

Vincent von Kaenel wrote:
> 
> Hello,
> I'm a new user of octave, so excuse my simple question.
> I have something like that in one of my script file for octave:
> 
> file_in=input("Enter the full name of the input file? ", "s");
> load (file_in);
> l=length(???); # I'd like the length of the matrix I just loaded here
> b=fft(???); # I'd like to take the fft of the matrix just loaded but I do
> not know the name of the variable...

Following your example very closely  you can do it like this:  

file_in=input("Enter the full name of the input file? ", "s");
load(file_in);
str=sprintf("l=length(%s);",file_in);
eval(str);
str=sprintf("b=fft(%s);",file_in);

However, this will not handle cases when the file begins with a number. 
It also does not handle cases when you have a '.' or other punctuation
in the file name.   I suggest a better way below.  

> The "input file" contains  x y data like:
> 
> 0 1
> 1 2
> 3 4
> 4 8
> ...
> 
> I would like to load this file in a specific variable name so that I can
> get the length of the matrix and process it. How can I do that when
> file_in may have different values?

use sprintf in conjunction with eval.    For example,  I have files with
one value on each line.   The number of data points is always a multiple
of 500.  Each set of 500 is one pulse from an oscilloscope.  I also had
to take into account that sometimes the file names began with a number
and Octave does not allow you to have variable names that start with a
number.   My function to load looks like this:

function pulses = get_pmt_data(file)
  str = sprintf("system(ŠÜ"ln -s %s temp.wavŠÜ");",file);
  eval(str);
  load temp.wav
  system("rm temp.wav");
  tmp_pulses = reshape(temp,500,max(size(temp))/500);
  pulses = translate_pulses(tmp_pulses);
endfunction

To read a file in from Octave I simply type:

data = get_pmt_data("2sab456.pul");
    
You probably want to remove the reshape and translate_pulses line.   
These are specific to my data set.   You might also want to think of a
better name than temp.wav.  It might remove the file if it already
existed in the current directory, which may not be acceptable for you.   

I hope I have been helpful.  Good luck.  

-- 
Ben Sapp                         Los Alamos National Laboratory
email: <mailto:address@hidden>   Phone: (505)667-3277
Fax:   (505)665-7920             URL:   http://www.neutrino.lanl.gov/
--



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]