Dear coder, Briefly, the program objective was to evaluate all possible constant pairs for a different set of condition. Since there are SIX constant, the current implementation required SIX nested FOR-loop. However, the code looks so messy.
for f_p_kdeA=s.p_kdeA for f_p_kdeF=s.p_kdeF for f_p_PrmSq00=s.p_PrmSq00 for f_p_PrmSq01=s.p_PrmSq01 for f_p_PrmSq10=s.p_PrmSq10 for f_p_PrmSq11=s.p_PrmSq11 s=eval_s(s); end end end end end end
Thus, I wonder how to make the following code to be more efficient by eliminating the FOR-loops. Thru some reading, using the NDGRID is a possible ways to make the code more efficient. However, I have limited knowledge on how to implement it. I really appreciate if someone can point out on how to do it.
The complete code is a below
[comb,s]=ini();comb= eval_forLoop(comb,s);result=array2table(comb);result.Properties.VariableNames=s.HeaderName;function [comb,s]=ini()load('stt_table.mat')data=table2array(stt_table);[s.state.kde,s.state.prm,s.state.sq]=deal(data(:,1),data(:,2),data(:,3));s.p_kdeA=0:0.5:1;s.p_kdeF=0:0.5:1;s.p_PrmSq00=0:0.5:1;s.p_PrmSq01=0:0.5:1;s.p_PrmSq10=0:0.5:1;s.p_PrmSq11=0:0.5:1;nRow=(numel(s.p_kdeA))*(numel(s.p_kdeF))*(numel(s.p_PrmSq00))*...(numel(s.p_PrmSq01))*(numel(s.p_PrmSq10))*(numel(s.p_PrmSq11));comb=nan(nRow,7);endfunction comb= eval_forLoop(comb,s)c_d=1;for f_p_kdeA=s.p_kdeA for f_p_kdeF=s.p_kdeF for f_p_PrmSq00=s.p_PrmSq00 for f_p_PrmSq01=s.p_PrmSq01 for f_p_PrmSq10=s.p_PrmSq10 for f_p_PrmSq11=s.p_PrmSq11 s.table1=[f_p_kdeA;f_p_kdeF]; s.table2=[f_p_PrmSq00;f_p_PrmSq01;f_p_PrmSq10;f_p_PrmSq11]; s=eval_s(s); comb(c_d,:)= [s.avrge_aa;f_p_kdeA;f_p_kdeF;f_p_PrmSq00;... f_p_PrmSq01; f_p_PrmSq10;f_p_PrmSq11]; c_d=c_d+1; end end end end end end end %
Best Answer