function y=K_val(K,x)
% function y=K_val(K,x)
% value of the kernel K in the point(s) x
% K- kernel (structure):
% K.type  - type of the kernel:
%      'opt' - optimal kernel (default)
%      'fun' - external function
%      'str' - string (variable denoted as 'x')
%      'pol' - polynomial kernel
% K.name - string with kernel expression or function name,
%               ignored for optimal and polynomial kernel
% K.coef - coefficients of the optimal or polynomial kernel
% K.support - suppoet of the kernel, default [-1,1]
% K.ny, K.k, K.mi - parameters of the kernel (order etc.)
% K.var  - variance of the kernel
% K.beta - k-th moment of the kernel
a=K.support(1);
b=K.support(2);
y=zeros(size(x));
I=find(x>=a & x<=b);
x=x(I);

switch K.type 
    case {'opt','pol'}
        y(I)=polyval(K.coef,x);
    case 'str'
        fs=K.name;
        fs=strrep(fs,'*','.*');
        fs=strrep(fs,'/','./');
        fs=strrep(fs,'^','.^');
        y(I)=eval(fs);
    case 'fun'
        y(I)=feval(K.name,x);
end
 