MATLAB Answers

How can I save my results of a loop in one table

2 ビュー (過去 30 日間)
Mustafa Vural
Mustafa Vural 2020 年 9 月 16 日
コメント済み: Star Strider 2020 年 9 月 17 日
I have 25 parameter combination in my code (b&T --> 1:5).
In the third part of my code I am doing the anderson darling test on my combinations.
It tells me if ONE combination ( for example b=1 and T=1) is a good combination or bad. I want to see the results for all 25 combination. But with this code, I only see the last combination of the loop.
How can I save them all in a table?
clear all;
n = 10;
t0 = 0.5;
b = 1:5;
T = 1:5;
for v_T= 1:length(T)
for v_b= 1:length(b)
data(:,v_b,v_T) = wblrnd(v_b,v_T, [n,1]) + t0;
start = [1 0 0];
custompdf = @(x,a,b,c) (x>c).*(b/(a-c)).*(((x-c)/(a-c)).^(b-1)).*exp(-((x-c)/(a-c)).^b);
opt = statset('MaxIter',1e3,'MaxFunEvals',1e3,'FunValCheck','off');
params(v_b,1:3,v_T) = mle(data(:,v_b,v_T),'pdf',custompdf,'start',start,'Options',opt,'LowerBound',[0 0 0],'UpperBound',[Inf Inf Inf])
end
end
for v_T= 1:length(T)
for v_b= 1:length(b)
T_A = T(v_T)
b_A = b(v_b)
dist = makedist('weibull','a',T_A,'b',b_A)
[h,p] = adtest(data(:, v_b, v_T),'Distribution',dist)
end
end

  0 件のコメント

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

採用された回答

Star Strider
Star Strider 2020 年 9 月 16 日
The adtest function returns scalars for the outputs, so something like this could work:
[h(v_b, v_T),p(v_b, v_T)] = adtest(data(:, v_b, v_T),'Distribution',dist);
That will save the results in their respective matrices.
I cannot run your code, so I cannot test that.

  14 件のコメント

表示 11 件の古いコメント
Star Strider
Star Strider 2020 年 9 月 17 日
I am not exactly certain how to create the table this time.
Try this:
[vT,vb] = meshgrid(1:length(T), 1:length(b));
T2p = array2table(result2p);
T3p = array2table(result3p);
T2 = [table(vT(:), vb(:), 'VariableNames',{'v_T','v_b'}), T2p, T3p];
creating 3 tables and concatenating them, with:
First9Rows = T2(1:9,:)
producing:
First9Rows =
9×16 table
v_T v_b result2p1 result2p2 result2p3 result2p4 result2p5 result2p6 result2p7 result3p1 result3p2 result3p3 result3p4 result3p5 result3p6 result3p7
___ ___ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________ _________
1 1 1.0287 1.0141 0 1 1 0 100 1.4767 0.96223 0.50666 1 1 0.5 100
1 2 1.0586 2.4242 0 1 2 0 100 1.5203 2.4382 0.43051 1 2 0.5 100
1 3 1.0107 3.6975 0 1 3 0 100 1.5031 2.6285 0.65671 1 3 0.5 100
1 4 0.96538 3.7811 0 1 4 0 100 1.5241 3.2105 0.73159 1 4 0.5 100
1 5 0.9754 5.0861 0 1 5 0 100 1.4811 5.481 0.37902 1 5 0.5 100
2 1 2.2783 1.0685 0 2 1 0 100 2.0837 0.8486 0.5487 2 1 0.5 100
2 2 2.0727 2.0381 0 2 2 0 100 2.6639 2.2925 0.54981 2 2 0.5 100
2 3 2.0826 3.1779 0 2 3 0 100 2.418 3.2345 0.38082 2 3 0.5 100
2 4 1.9133 3.394 0 2 4 0 100 2.3779 4.874 0.32657 2 4 0.5 100
I am using those matrices because ‘param2p’ and ‘param3p’ are both (5x7x5) matrices, and I cannot figure out how to create them as 2D matrices to create the table object, and be consistent with the ‘v_T’ and ‘v_b’ subscripts.
.
Mustafa Vural
Mustafa Vural 2020 年 9 月 17 日
It looks really good, I really appreciate it. Thank you, you helped me a lot.
Star Strider
Star Strider 2020 年 9 月 17 日
As always, my pleasure!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by