1

I have in MATLAB a cell array C containing containing n function handles @(t). I also have a vector x_star containing n constants. I am now trying to make a new function handle consisting of the function on location i in the cell array times the constant on location i in the vector. I have been trying with this code but it just outputs "index exceeds matrix dimensions":

M= @(t) 0;
for i=1:length(x_star)
M = @(t) M(t)+ C{i}(t)*x_star(i);
end

Is it possible to do it like this or is there a more convenient way to do it?

And x_star and C is defined by:

w=2*pi/24; 
C = cell(n,1);       
C{1}=@(t) 1;
for i=2:n
    if (mod(i,2)==0)               
        f = @(t) sin(0.5*i*w*t);
    else
        f = @(t) cos(0.5*(i-1)*w*t);
    end
C{i}=f;
end


 A = zeros(length(t),n);     %% Initialize A-matrix
A(:,1)=C{1};
for i=2:n
        A(:,i)=C{i}(t);
end
x_star = (transpose(A)*A)\transpose(A)*y;   
r_star=y-A*x_star;            
some_name
  • 389
  • 3
  • 17

0 Answers0