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:
Arithmetic deduction/extraction

Subject: Arithmetic deduction/extraction

From: kees de Kapper

Date: 11 Apr, 2013 14:13:09

Message: 1 of 4

Hi All,

Although this is not purely Matlab related, I need for a matlab script. Hopefully some of you could help me with this.

Consider a a formula like: (2*A+(B.^2+1)/3)

How could I split this in separate arithmetic operations on a most efficient way.

I need to process a formula-string that a user can give in a dlg. Each variable needs some processing in a separate function.

Is there an unambiguous way of doing this?

thanks in advance,

Kees

Subject: Arithmetic deduction/extraction

From: Steven_Lord

Date: 11 Apr, 2013 15:49:54

Message: 2 of 4



"kees de Kapper" <kees_de_kapper@hotmail.com> wrote in message
news:kk6gdl$8jq$1@newscl01ah.mathworks.com...
> Hi All,
>
> Although this is not purely Matlab related, I need for a matlab script.
> Hopefully some of you could help me with this.
>
> Consider a a formula like: (2*A+(B.^2+1)/3)
>
> How could I split this in separate arithmetic operations on a most
> efficient way.

I have a question and some clarifications requests.

Please clarify what YOU mean by "most efficient way" (wall clock time, CPU
time, number of operations, minimal memory allocation, etc.) and specify
what arithmetic operations you're allowed to use.

For instance, there's no FMA operation
(http://en.wikipedia.org/wiki/Multiply%E2%80%93accumulate_operation) in
MATLAB but certain expressions simplify down to one operation if you're
allowed to include that in your instruction set.

Similarly, do you count sin(x) as one "arithmetic operation" or do you need
to count all the additions, multiplications, etc. required to implement
CORDIC (http://en.wikipedia.org/wiki/CORDIC) or FDLIBM
(http://www.netlib.org/fdlibm/) in your count?

The question I have (I consider all the above as clarification) is why are
you doing this? What is your end goal in doing this?

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

Subject: Arithmetic deduction/extraction

From: kees de Kapper

Date: 11 Apr, 2013 20:20:21

Message: 3 of 4

Thanks for replying. I'm going to look into it.

What I'm trying to make is a simple way for users to apply arithmetic operation of loaded images. I've created an Image-Object that contains multiple properties and methods which make the use of images much more elegant. If I have to do Arithmetic operations it is now very easy and robust.
Now, I'd like to enable this "interface" for users. If a user now writes "2*Img1+Img3/Img5" I need to extract all the operations and excecute some methods/functions for example cropping, transformations etc. "Img1*2" is straight forward to extract, but "(2*Img1+Img2)/3" is not.
Could this easily be done in Matlab?

Thanks for considering.

Kees

Subject: Arithmetic deduction/extraction

From: Steven_Lord

Date: 12 Apr, 2013 17:26:30

Message: 4 of 4



"kees de Kapper" <kees_de_kapper@hotmail.com> wrote in message
news:kk75u5$kf5$1@newscl01ah.mathworks.com...
> Thanks for replying. I'm going to look into it.
>
> What I'm trying to make is a simple way for users to apply arithmetic
> operation of loaded images. I've created an Image-Object that contains
> multiple properties and methods which make the use of images much more
> elegant. If I have to do Arithmetic operations it is now very easy and
> robust. Now, I'd like to enable this "interface" for users. If a user now
> writes "2*Img1+Img3/Img5" I need to extract all the operations and
> excecute some methods/functions for example cropping, transformations etc.
> "Img1*2" is straight forward to extract, but "(2*Img1+Img2)/3" is not.
> Could this easily be done in Matlab?

Could this be done? Yes.
Could this _easily_ be done? Yesssssssssss, I can think of a way to apply
those formulae to the images ... but doing so would require using EVAL and I
discourage you from doing that because that's handing a loaded weapon to
your users.

Since you said you're doing this in a GUI (dialog) have you considered
putting buttons for the arithmetic operations you want to support on the GUI
itself? That way you allow your users to only manipulate the images using
the arithmetic operations YOU give them rather than giving them the freedom
to do anything (what happens if your user types a system command into your
dialog, such as the command to format the hard drive?) There's an example in
Symbolic Math Toolbox, FUNTOOL, that does basically what I'm thinking.

http://www.mathworks.com/help/symbolic/funtool.html

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

Tags for 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