Hi, I have a for loop where d is a 100×1 array and d0 is the average value of the elements in d. I would like to know how I can change it so after each iteration I have a 100×1 result in final_table and after all iterations are completed the variable final_table is a 100×100 array. The way I have implemented the if loop is incorrect since I finish with a 50×100 array. What I am trying to implement is to go through the different values of d, if less than the average d0 then calculate final (variables final_N1 and final_No) to hopefully finish with a 100×1 result and repeat 100 times to finish with 100×100 array in final_table. Thanks.
for cnt=1:100 if d(cnt)<=d0 No=sum(d<=d0); d_pos_No=find(d<=d0); d_pos_No=d(d_pos_No); final_No=d_pos_No/No; final_N1=zeros(size(final_No)); else N1=sum(d>d0); d_pos_N1=find(d>d0); d_pos_N1=d(d_pos_N1); final_N1=d_pos_N1/No; final_No=zeros(size(final_N1)); end final_table(1:numel(final_No+final_N1),cnt)=final_No+final_N1;end
Best Answer