From: tz on 23 Feb 2010 07:27 Hi, I'm trying to build a function that will load a file, according to a filename given by the user calling the function. Meaning, the function should look something like this (as far as I understand): (function name: getFile) function [output]= getFile('fileName') load 'fileName' (Output is in a further stage, after loading the file) This form does not work any ideas on how to do this? What should I do?
From: Rune Allnor on 23 Feb 2010 08:01 On 23 Feb, 13:27, "tz " <tzach.au...(a)gmail.com> wrote: > Hi, > I'm trying to build a function that will load a file, according to a filename given by the user calling the function. Meaning, the function should look something like this (as far as I understand): > > (function name: getFile) > > function [output]= getFile('fileName') > load 'fileName' > > (Output is in a further stage, after loading the file) > > This form does not work any ideas on how to do this? > What should I do? Use the function form of LOAD: function [output]= getFile('fileName') output = load('fileName') Rune
From: tz on 23 Feb 2010 08:14 I didn't think of that... Ill give it a try! Thanks!
From: Steven Lord on 23 Feb 2010 09:56 "tz " <tzach.auman(a)gmail.com> wrote in message news:hm0hin$gln$1(a)fred.mathworks.com... > Hi, > I'm trying to build a function that will load a file, according to a > filename given by the user calling the function. Meaning, the function > should look something like this (as far as I understand): > (function name: getFile) > > function [output]= getFile('fileName') > load 'fileName' > > (Output is in a further stage, after loading the file) > > This form does not work any ideas on how to do this? > What should I do? As Rune said, use the functional form -- but you need to change your function declaration line a little bit. The input argument specified in the function declaration cannot be a string or an expression; it MUST be the name of a variable. [Now when you _call_ the function, you can call it with whatever you want as the input -- string, expression, whatever.] In addition, when using the functional form, these two commands are quite different: load('fileName') load(fileName) The former attempts to load the file whose name is either fileName or fileName.mat -- the latter attempts to load in the file whose name is stored in the variable fileName. function output = getFile(fileName) S = load(fileName); -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: Using csaps Cubic Smoothing spline Next: solving modified rayleigh plesset equation |