Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Creating an anonymous function in real time

Subject: Creating an anonymous function in real time

From: Jerry Walker

Date: 22 Jun, 2011 22:41:02

Message: 1 of 3

I would like to be able to enter and change the defined portion of an anonymous function as part of the input as with other parameters. For example the following integration problem:

jfactor = @(r,theta,phi) input('Enter an expression for the Current Density (J)... > ');


for theta = ithetar:dt:fthetar,
   
    for phi = iphir:dp:fphir,

% add the partial sums to the total sum

sum=sum + jfactor*r^2*sin(theta)*dt*dp;
  
    end
end

MATLAB will not accept my first line as a legitimate anonymous function.

Subject: Creating an anonymous function in real time

From: Paulo Silva

Date: 22 Jun, 2011 23:04:04

Message: 2 of 3

exp=input('Enter an expression>','s')
jfactor = eval(['@(r,theta,phi)' exp])

Subject: Creating an anonymous function in real time

From: Steven_Lord

Date: 23 Jun, 2011 15:41:37

Message: 3 of 3



"Jerry Walker" <tateshell@yahoo.com> wrote in message
news:ittr1u$q34$1@newscl01ah.mathworks.com...
> I would like to be able to enter and change the defined portion of an
> anonymous function as part of the input as with other parameters. For
> example the following integration problem:
>
> jfactor = @(r,theta,phi) input('Enter an expression for the Current
> Density (J)... > ');
>
> for theta = ithetar:dt:fthetar, for phi = iphir:dp:fphir,
> % add the partial sums to the total sum
>
> sum=sum + jfactor*r^2*sin(theta)*dt*dp;

Don't use SUM as a variable, for if you do you won't be able to use the SUM
function in the function in which you do.

http://www.mathworks.com/help/techdoc/ref/sum.html

> end end
> MATLAB will not accept my first line as a legitimate anonymous function.

Can you clarify what you mean? What exact behavior are you seeing (warning,
error, answer different than you expect, etc.?)

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us