取一组随机坐标(x,y,z),它将成为我的3x3x3矩阵的中心(也被视为局部最小值).我有一个函数J,它接受那些坐标,进行计算并返回一个数字.如果这26个点中的任何一个更小,那将是我下一个矩阵的中心.如果我没有找到一个较小的值,矩阵的半径增加1,我们再次运行循环.我的问题是:如何仅通过多维数据集的"shell"循环而不调用以前测试的值的函数?
我试着在下面说明它(这里是2d,但你明白了)..点是被测试的值,"?" 需要计算并与当地最小值进行比较的是那些.
这是代码
minim=100;
%%the initial size of the search matrix 2*level +1
level=1;
x=input('Enter the starting coordinate for X : ');
y=input('Enter the starting coordinate for Y : ');
z=input('Enter the starting coordinate for Z : ');
%%The loop
if(level<=10)
for m=x-level:x+level
for n=y-level:y+level
for p=z-level:z+level
A(m,n,p)=J(m,n,p);
if A(m,n,p)<minim
minim=A(m,n,p);
x=m;y=n;z=p;
level=1;
else
level=level+1;
%<<----shell loop here ---->>
end
end
end
end
else
%Display global min
display(minim, 'Minim');
%Coordinates of the global min
[r,c,d] = ind2sub(size(A),find(A ==minim)); …Run Code Online (Sandbox Code Playgroud) Country- Company有一个1-n的关系.
Company- Dish有一段关系.
我需要根据各自区域设置中的计数从每个区域设置中获取Dishes,每个区域设置有100个结果.
到目前为止我有
SELECT dishes.title,
dishes.name,
dishes.id,
countries.locale
FROM countries
JOIN companies ON companies.`country_id` = countries.`id`
JOIN company_dish ON company_dish.`company_id` = companies.`id`
JOIN dishes ON company_dish.`dish_id` = dishes.`id`
GROUP BY dishes.`title`, countries.locale
ORDER BY ??? count_dishes_in_each_locale ?? DESC
Run Code Online (Sandbox Code Playgroud)
样本数据:
期望的输出:
我怎样才能做到这一点?