Hello Mustafa, when you preallocate the variable params, you have a little twist in there, since you defined it as having the same size as data. However, params has b_A as first, n as second and T_A as third dimension. Later you retrieve data (mle...), it seems like you want to save it as the first 3 elements of the second dim of params. But on the right side you tell MATLAB you want to put it in all 10 columns(i,:,k), which gives you an error (also, you are only specifying the second dimension to element 6, if you don't want the rest to be zeros, you have to replace n by 6).

For the rest I changed some things I could quickly recognize as being redundant:

- you are having four for-loops, which can be put together. For-loops are slow and from your code I did not see why you made "a second round".
- you are writing for i = 1:length(T_A), which in the case of a vector of integers from one is the same as writing for i = T_A. Also you do not have to index into T_A/b_A to retrieve the data (T_A(k)) because it is always k or i

clear;

clc;

n = 10;

t0 = 0.5;

b_A = 1:5;

T_A = 1:5;

LowerBound= [0 0 0];

rng('shuffle');

data = zeros(n,length(b_A),length(T_A));

params = zeros(length(b_A),n,length(T_A));

for k= T_A

for i= b_A

data(:,i,k) = wblrnd(i,k, [n,1]) + t0;

start = [i k t0];

custompdf = @(x,a,b,c) (x>c).*(b/a).*(((x-c)/a).^(b-1)).*exp(-((x-c)/a).^b);

opt = statset('MaxIter',1e5,'MaxFunEvals',1e5,'FunValCheck','off');

params(i,1:3,k) = mle(data(:,i,k),'pdf',custompdf,'start',start,'Options',opt,'LowerBound',LowerBound,'UpperBound',[Inf Inf min(data(:,i,k))])

params(i,4,k) = i;

params(i,5,k) = k;

params(i,6,k) = t0;

end

end

I think it should still work as you want it, but you should check the arrays, better safe than sorry!

P.S I do not know about weibul distribution and whether your code does what it should, I just looked at the code itself.

sry for all the editing

## 0 Comments

Sign in to comment.