Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: store functions in a struct
Replies: 1   Last Post: Dec 4, 2012 10:33 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Joao Posts: 1 Registered: 12/4/12
store functions in a struct
Posted: Dec 4, 2012 9:52 AM
 Plain Text Reply

is it possible to store functions in a structure?
I need to use each output for this function X, and the problem is that the length of the vectors that come out is variable, so i cant store it in a normal matix.
I tried this:

ponderadoresSimpson=struct('LAX0','ponderadores_Simpson = Calc_Ponderador_Simpson(LAX0)','LAX2','ponderadores_Simpson = Calc_Ponderador_Simpson(LAX2)','LAX4','ponderadores_Simpson = Calc_Ponderador_Simpson(LAX4)','LAX6','ponderadores_Simpson = Calc_Ponderador_Simpson(LAX6)','LAX8','ponderadores_Simpson = Calc_Ponderador_Simpson(LAX8)','LAX10','ponderadores_Simpson = Calc_Ponderador_Simpson(LAX10)','LAX12','ponderadores_Simpson = Calc_Ponderador_Simpson(LAX12)','LAX14','ponderadores_Simpson = Calc_Ponderador_Simpson(LAX14)');

but the fields are mere strings and do not work as a function.
Is there any specific way to do it or an different way to store the vectors?

this is the function:

function [ponderador_Simpson] = Calc_Ponderador_Simpson(Vector)

contador = 1;
while contador < length(Vector)
a = Vector(contador);
contador = contador + 1;
b = Vector(contador);
Espacamentos(contador-1) = b-a;
end

i = 1;
ponderador_Simpson(1) = 0;
while i < length(Espacamentos)
if abs(Espacamentos(i) - Espacamentos(i+1)) < 0.000001 ;
ponderador_Simpson(i) = ponderador_Simpson(i) + (1/3) * Espacamentos(i);
ponderador_Simpson(i+1) = (4/3) * Espacamentos(i);
ponderador_Simpson(i+2) = (1/3) * Espacamentos(i);
i = i + 2;
else
ponderador_Simpson(i) = ponderador_Simpson(i) + (1/2) * Espacamentos(i);
ponderador_Simpson(i+1) = (1/2) * Espacamentos(i);
i = i + 1;
end
end
if i == length(Espacamentos)
ponderador_Simpson(i) = ponderador_Simpson(i) + (1/2) * Espacamentos(i);
ponderador_Simpson(i+1) = (1/2) * Espacamentos(i);
else
end
end

thank you

Date Subject Author
12/4/12 Joao
12/4/12 Nasser Abbasi

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.