[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to allow for a parameter when callling another function
From: |
Olaf Till |
Subject: |
Re: How to allow for a parameter when callling another function |
Date: |
Wed, 4 May 2011 07:48:31 +0200 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Tue, May 03, 2011 at 06:09:24PM -0700, clustro wrote:
> Hi there,
>
> I am programming a function that minimizes another function. I call the
> function like this:
>
> Data = mcsa('ackley',x0)
>
> where:
>
> Data is the output (not important)
> 'ackley' is a function I wish to minimize (I have others; this is just an
> example)
> x0 is the initial-geuss vector.
>
> Now, the ackley function, among others, can be altered by a parameter, n.
> Currently, if I want to change n, I must manually go into ackley.m, change
> it, and run the code again.
>
> It would be more convenient if I could do it all in one shot. I tried
> changing ackley to be y = ackley(x,n)
> (and commented out n in the rest of the code),
I don't understand what you mean by this ... why have you commented it
out?
> and ran the code like this:
>
> Data = mcsa(@(x) ackley(x,n),x0)
That is normally a good way, but you seem to have made some mistake
which is hard to guess from the information you provide.
> But I get:
>
> error: subscript indices must be either positive integers or logicals.
>
> The error is on the first line where I use the "feval" function. Changing
> @(x) ackley(x,n) to a string did not work either; Octave just didn't find
> the file then.
I suggest you show us at least the header and this first line of your
function, and tell us what is in the variable 'n'.
Olaf