MATLAB Answers

Results as a loop

1 ビュー (過去 30 日間)
Mustafa Vural
Mustafa Vural 2020 年 6 月 20 日
編集済み: KALYAN ACHARJYA 2020 年 6 月 21 日
I want to make my results as a loop.
When I change the parameter b_A or T_A from 1:5 to 1:3, I want that my results also change. But with this code, I need to change manually the result code, every time I change the loop of the parameter. Can someone help me plz?
This code is to estimate a 3 parameter weilbul distribution.
clear all
n = 1000;
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),length(T_A));
data2P = zeros(n,length(b_A),length(T_A));
params2p = zeros(length(b_A),4,length(T_A));
for k= T_A
for i= b_A
data(:,i,k) = wblrnd(i,k, [n,1]) + t0;
data2P(:,i,k) = wblrnd(b_A(i),T_A(k), [n,1]);
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;
params2p(i,1:2,k) = wblfit(data2P(:,i,k));
params2p(i,3,k) = i;
params2p(i,4,k) = k;
end
end
result(1:5,:)= params(:,:,1);
result(6:10,:)= params(:,:,2);
result(11:15,:)= params(:,:,3);
result(16:20,:)= params(:,:,4);
result(21:25,:)= params(:,:,5);

  2 件のコメント

Image Analyst
Image Analyst 2020 年 6 月 20 日
If you don't want to change them by changing your code, how do you want to change them? Where would you change these values if not in your code? Do you want to make a list of the starting and stopping values in a text file or somewhere, that your code read in? Do you want your code to ask the user? I have no idea - you forgot to say.
Mustafa Vural
Mustafa Vural 2020 年 6 月 21 日
Oh I am sorry,
at the end you see:
result(1:5,:)= params(:,:,1);
result(6:10,:)= params(:,:,2);
result(11:15,:)= params(:,:,3);
result(16:20,:)= params(:,:,4);
result(21:25,:)= params(:,:,5);
this is specially for the parameters b=1:5 and T=1:5. You see the lines:
result(1:5,:)
result(6:10,:) and so on.
But when I change for example T to 1:3, I need to change the code like:
result(1:3,:)
(result(4:6,:) and so on.
Now I want to create a code, that it changes automatically when I change my parameter b and T.
Have you any idea?

サインインしてコメントする。

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 6 月 21 日
編集済み: KALYAN ACHARJYA 2020 年 6 月 21 日
%Last section
data1=0;
results=[];
for i=1:length(T)
result(b+data1,:)= params(:,:,T(i));
data1=data1+5;
end

  2 件のコメント

madhan ravi
madhan ravi 2020 年 6 月 21 日
Preallocation?
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 6 月 21 日
Thanks Madhan, sorry again, I missed the same. But, I have no idea about exact size of results, its depends on b, and author said it can be change any sizes.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by