how to vary data length in the given code.There are 7 sites an each site having different data length.For example n1=18, n2=29 and so on N=number of sites are 7.

1 次查看(过去 30 天)
for i=1:500
for j=1:7
b0(j,:,i)=D(j,:,i)/46;
for k=1:45
b1(j,k,i)=(D(j,k,i)*(46-k))/(46*45);
for m= 1:44
b2(j,m,i)=(D(j,m,i)*(46-m)*(46-m-1))/(46*45*44);
for n=1:43
b3(j,n,i)=(D(j,n,i)*(46-n)*(46-n-1)*(46-n-2))/(46*45*44*43);
end
end
end
end
end
  6 个评论
dpb
dpb 2022-5-6
First, turn the calculation into a function that operates over the size of the inputs passed into it instead of hardcoding fixed limits for loops.
Then read in the data for each case into an array and call your function with it.
As noted above, the problem arises when you use hardcoded constants in the code instead of variables and also in not factoring out the code that does the same operations over each data set into a separate, callable function.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by