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:
read a function from a excel file?

Subject: read a function from a excel file?

From: Claudio Barrientos

Date: 22 Jan, 2009 12:34:02

Message: 1 of 6

Hi

How I can read a function from a excel file?..... I mean the cell c:2 has '3v1+v2-v3' (or any function like that with, N variables)

and in the other hand I have a matrix V(comb,N)....where comb = number of combination possibles with N variables
for example:
v1=[1 2 3]
v2=[0 1]
v3=[10 20]
V=[1,0,1; 1,1,10; 1,0,20; 1,1,20....etc (all combinations)]


and I want to evaluate the value Y='3v1+v2-v3' (obtained from excel) for each row of the V matrix.....

Subject: read a function from a excel file?

From: Claudio Barrientos

Date: 22 Jan, 2009 12:38:02

Message: 2 of 6

I need to known how I can read the excel's cell & MatLab takes it like a function Y

I hope that you can help me... like many other previous times

Thanks!!

Subject: read a function from a excel file?

From: Dave Brackett

Date: 22 Jan, 2009 13:37:02

Message: 3 of 6

"Claudio Barrientos" <cbarrientos025@gmail.com> wrote in message <gl9pba$6l8$1@fred.mathworks.com>...
> I need to known how I can read the excel's cell & MatLab takes it like a function Y
>
> I hope that you can help me... like many other previous times
>
> Thanks!!

speaking personally, i can't really understand what you mean. can you clarify? why do you need the function from excel? can't you just write a new function in matlab?

Subject: read a function from a excel file?

From: Claudio Barrientos

Date: 22 Jan, 2009 13:53:01

Message: 4 of 6

> speaking personally, i can't really understand what you mean. can you clarify? why do you need the function from excel? can't you just write a new function in matlab?

I need extract the function from another place (excel form example).... It means I need that the function Y don't be part of the MatLab code.... take the function from another place and locate it inside the code

I'm making a MatLab program that take a function Y, and the min,max & step of each variable of the function Y... and the program must calculate the value of Y for each possible combination of entry variables.... that's must be for any function & any cant of variables

It's more clear?... I hope so :D

greets & thanks!

Subject: read a function from a excel file?

From: Steven Lord

Date: 22 Jan, 2009 14:45:24

Message: 5 of 6


"Claudio Barrientos" <cbarrientos025@gmail.com> wrote in message
news:gl9tnt$ivj$1@fred.mathworks.com...
>> speaking personally, i can't really understand what you mean. can you
>> clarify? why do you need the function from excel? can't you just write a
>> new function in matlab?
>
> I need extract the function from another place (excel form example).... It
> means I need that the function Y don't be part of the MatLab code.... take
> the function from another place and locate it inside the code
>
> I'm making a MatLab program that take a function Y, and the min,max & step
> of each variable of the function Y... and the program must calculate the
> value of Y for each possible combination of entry variables.... that's
> must be for any function & any cant of variables
>
> It's more clear?... I hope so :D

It's clear, but without additional constraints it's going to be difficult or
impossible to achive the goal as described.

The general procedure I'd follow is:

1) Read the string from Excel using the COM interface or XLSREAD.
2) Determine what variable names the string contains.
3) Construct an inline object or an anonymous function (using EVAL --
creation of a anonymous function handle from a string is one task that
currently requires EVAL) or write the function out as an M-file using FOPEN,
FPRINTF, FCLOSE.
4) Invoke the inline object, anonymous function, or the created function
with the appropriate parameters.

Alternately, you could replace steps 2 and 3 with calls to SYM and
MATLABFUNCTION if you have version 5.0 or later of Symbolic Math Toolbox.

http://www.mathworks.com/access/helpdesk/help/toolbox/symbolic/matlabfunction.html


Now why do I say that this task is going to be difficult or impossible to
achieve?

What if your formula includes a call to the Excel function FACTDOUBLE, for
which there is no equivalent included as part of MATLAB? Easy enough, just
write your own FACTDOUBLE:

function y = factdouble(x)
% http://en.wikipedia.org/wiki/Factorial#Double_factorial
y = prod(x:-2:1);

What if your formula included a call to Excel's TBILLPRICE function? Well,
okay, you can implement your own using Financial Toolbox.

There are a lot of functions available to Excel. I can keep asking
questions about different functions all day. Some have direct equivalents
in MATLAB. Some don't, but can be implemented in MATLAB. But what's the
MATLAB equivalent of GETPIVOTDATA, for instance?

--
Steve Lord
slord@mathworks.com

Subject: read a function from a excel file?

From: David

Date: 22 Jan, 2009 14:48:02

Message: 6 of 6

"Claudio Barrientos" <cbarrientos025@gmail.com> wrote in message <gl9tnt$ivj$1@fred.mathworks.com>...
> > speaking personally, i can't really understand what you mean. can you clarify? why do you need the function from excel? can't you just write a new function in matlab?
>
> I need extract the function from another place (excel form example).... It means I need that the function Y don't be part of the MatLab code.... take the function from another place and locate it inside the code
>
> I'm making a MatLab program that take a function Y, and the min,max & step of each variable of the function Y... and the program must calculate the value of Y for each possible combination of entry variables.... that's must be for any function & any cant of variables
>
> It's more clear?... I hope so :D
>
> greets & thanks!

i am making a wild guess that you want to read in a string from somewhere else, maybe excel, then evaluate it like a matlab formula. if that is the case then look up the 'eval' function.

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