shrey
shrey

Reputation: 223

fminsearch syntax in Matlab

I was going through this code in Matlab. Can someone explain the syntax part of line 4 (fminsearch)-what does the [] signify.

function [v_opt]=optdc_fv(Data,dt,x,f,v0)
v_opt=zeros(length(f),1); 
for i=1:length(f)
v_opt(i)=fminsearch(@costf_fv, v0(i), [], Data, dt, x, f(i)); 
end

Here costf_fv is the cost function

function cf=costf_fv(v, Data, dt, x, fi)
[N, Ch]=size(Data); % No. of data, No. of channel
t=[0:dt:(N-1)*dt]';
lamda=v./fi; %  edited part
%  Discrete Time Fourier Transform in time domain
[xx, tt]=meshgrid(x,t);
j=sqrt(-1);
tmp1=exp(-j*2*pi*fi*tt);
tmp2=Data.*tmp1; 
Ui=sum(tmp2); 
% Discrete Space Fourier transform --> velocity domain
tmp1=exp(j*2*pi/lamda*x'); 
tmp2=Ui.*tmp1; 
UUi=sum(tmp2); 
cf=-(abs(UUi)); % f-v Spectrum : edited part

Upvotes: 1

Views: 136

Answers (1)

Matt
Matt

Reputation: 13943

I did some tests with the fminsearch-function and it turns out, that the value [] is just a placeholder, instead of writing an arbitrary number. If you call...

fminsearch(@costf_fv, v0(i), [], Data, dt, x, f(i));

... then @costf_fv is the function handle and v0(i) is the starting point. The following five arguments are the arguments for your function cost_fv.

The algorithm behind fminsearch adjusts a specific value of your function in every iteration. This value is the first argument of cost_fv and is exactly at the position of [].

No matter what value you provide instead of [], it will be overwritten (even in the first iteration) by fminsearch. Therefore it is replaced by [] to show explicitly that there is no need to provide the value yourself.

Upvotes: 1

Related Questions