Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: input problems: beginner in matlab
Date: Mon, 17 Sep 2007 21:04:38 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 41
Message-ID: <fcmq56$i9h$1@fred.mathworks.com>
References: <fcmp9t$3vj$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1190063078 18737 172.30.248.35 (17 Sep 2007 21:04:38 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 17 Sep 2007 21:04:38 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 260670
Xref: news.mathworks.com comp.soft-sys.matlab:428990



Is this what you mean?

x=[1:1:10];
funct = input('function to evaluate = ','s');
to_evaluate = [funct '(x)'];
y = eval(to_evaluate)

(should work if you input the correct built in matlab
function names... ie sin, cos, tan, etc...)

Might be a better way to do it, but I think that might work.

--Travis

"Eddy " <grotehaas@mathworks.com> wrote in message
<fcmp9t$3vj$1@fred.mathworks.com>...
> x=[1:1:10]
> fprintf('please enter a function like sin cos exp etc,\n')
> fprintf('the calculation performed will be like
> pfun(funct(x)),\n')
> fprintf('where funct is your function and x= 0 to 10
> increment with 1,\n')
> funct=input('function funct=','s')
> pfun=funct'(x)'
> 
> In the technical course we are starting to learn Matlab for
> signal processing.
> So now we have to do all kinds of exercises, and I do like it.
> But one thing does not fall in to place.
> In the above script I prompt for a input from the user and
> store this in a variable 'funct' the input is as a string.
> now I want to use what is in the string to doe some
> computing but this last step will not succeed.
> So if the input would be sin the computation should be sin(x)
> 
> Can somebody help me with this probably syntax problem??
> 
> thanks
> 
> Eddy