Syntax for matlabFunction to produce vector variables and scalar variables

8 views (last 30 days)
When doing this:
syms x y z t
r = (x^2 + y^2 + z^2)*exp(-t);
matlabFunction(r, 'file', 'my_function',...
'vars', {t, [x y z]});
The resulting function operates on vectors:
function r = my_function(t,in2)
%MY_FUNCTION
% R = MY_FUNCTION(T,IN2)
x = in2(:,1);
y = in2(:,2);
z = in2(:,3);
r = exp(-t).*(x.^2+y.^2+z.^2);
How should I write matlabFunction if want the following;
function r = my_function(t,in2)
%MY_FUNCTION
% R = MY_FUNCTION(T,IN2)
x = in2(1);
y = in2(2);
z = in2(3);

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 30 Jan 2013
function [x,y,z] = my_function(t,in2)
  3 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 30 Jan 2013
You said, in my initial post matlabFunction returns in2 , in2 is an input to your function not an ouput
Giorgos Papakonstantinou
Giorgos Papakonstantinou on 30 Jan 2013
In the documentation you can find this http://www.mathworks.com/help/symbolic/matlabfunction.html. I meant that the command matlabFunction in the specific example creates a function with one output and two inputs. The two inputs of the generated function are in2 and t. The variable in2 in the generated function is a matrix. However, I want to create a function with the command matlabFunction that will generate a function with two inputs, of which one will be a vector and not a matrix. So I would like someone's help with the syntax of the command matlabFunction in order to achieve what I want. Is it more clear now?

Sign in to comment.


Giorgos Papakonstantinou
Giorgos Papakonstantinou on 30 Jan 2013
In the example that I showed in my initial post matlabFunction returns in2 as a matrix whereas I need a in2 to be a vector.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!