- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于一个项目,我尝试使用 matlab 调用另一个 .m 文件中的函数。然而,它说“没有足够的输入参数”,即使我确实传递了我相当确定的足够的输入参数。
在 eval_square.m 中:
function f = eval_square(x)
% fitness function of the magic square
%
% Parameters
% ----------
% x : array, the solution vector that represents a magic square.
% By default, the solution vector is converted to a magic square
% columnwisely.
% Output
% ----------
% f : double, the error value of the input solution vector.
% the mean squared error (MSE) of all each row, column and
% diagonal sum to the magic constant is computed
%
n = sqrt(length(x));
%More stuff, but error occurs at this line.
在 MYNAME_sa.m 中:
function [xopt, fopt] = MYNAME_sa(dim, eval_budget, fitness_func)
%Stuff
if dim == 2
len = 12^2; % length of the solution vector, shoud be 12^2
% when dim == 2
elseif dim == 3
len = 7^3; % length of the solution vector, shoud be 7^3 when
% dim == 3
end
%Stuff
s = randperm(len)
f = fitness_func(s)
%More stuff.
它应该评估长度为 12^2 的随机排列作为魔方,看看它与最佳值有多接近(即它与实际魔方有多接近),理论上对于魔方来说也是如此(eval_cube),但出现同样的错误。
有问题的错误:
>> MYNAME_sa(2, 10000, eval_square)
Error using eval_square (line 18)
Not enough input arguments.
Note that line 18 is n = sqrt(length(x));
如果我将 eval_square 硬编码到函数中并不重要 - 它似乎明白我想调用 eval_square 就好,但它只是不传递 s 或其他东西?我不明白为什么。我也尝试将 n 硬编码为 12,但这也不起作用,当我尝试实际使用 x 时会弹出错误。将 Fitness_func 更改为 @fitness_func 也不会改变任何内容。所以我的问题是,为什么会发生这种情况以及如何解决它?
最佳答案
尝试使用
MYNAME_sa(2, 10000, @eval_square)
关于MATLAB 奇数 'Too many input arguments' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47636391/
我的任务是编写一个java程序,首先询问用户将输入多少个数字,然后输出输入的奇数和偶数个数。它限制为整数 0-100。我的问题是:我的代码中缺少什么? import java.util.Scanner
我正在寻找有关 VBA 脚本的帮助。我一直在试图弄清楚如何使用 mod 功能。 这是我到目前为止所做的: Function AddOddNumbersWithMod(nr) Dim i, su
我只是想从 .NET 调用 kernel32 中的 GetPrivateProfileString 和 GetPrivateProfileSection,但遇到了一些我不明白的奇怪问题。 让我们从这个
我需要做的是在列表中交替应用 2 个函数。例如: (*2) (-3) [4,5,6,7,8] 会导致[8,2,12,4,16] , 因为 4*2 , 5-3 , 6*2 , 7-3 , 8*2 ...
我尝试在 JavaScript 中创建一个函数来判断一个数字是否为偶数,或者它是否是一个数字。我收到此错误: 这是 CodeCademy 中的类(class)。 最佳答案 您正在检查函数 isNaN
当我运行此命令时,不会打印任何内容,我尝试根据用户输入的内容打印一条消息,显示奇数或偶数。 import java.util.Scanner; public class Questions {
我必须编写一个程序来读取 3 个数字(使用输入框),并根据它们的值写入以下消息之一: 所有 3 个数字都是奇数或 所有 3 个数字都是偶数或 2 个数字是奇数,1 个数字是偶数或 1 个数字是奇数
我正在构建一个谷歌图像搜索的示例。我有一个图像网格(搜索结果)。当单击其中一张图像时,我正在使用 jquery 创建的部分标记中加载 html 文档。奇怪的是,如果你查看开发人员工具,html 已加载
我试图仅在偶数行上打印单词 * Even * ,而不包括第一行和第二行(最终不包括最后两行),但它打印 15 行,然后在整个过程中随机打印 * Even * 。使用 6 表示宽度,使用 15 表示高度
我有一个数学函数,它取决于由 给出的三个变量 {n、a 和 b} {a = n+1, b=n} 当 n 为偶数时 {b = n+1, a=n} 当 n 为奇数时 我的函数被调用了很多 次,n 各不相同
我有一个查询,其中有一个条件来检查房间号是否为奇数/偶数。问题在于房间号与建筑物信息一起存储在字符串中。 以下是数据库中数据的格式: ABC-0101A (Odd) ABC-0112B (Even
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我有一个包含类似内容的页面。 ################################# # __________________________ # # | |
这个问题在这里已经有了答案: Can I combine :nth-child() or :nth-of-type() with an arbitrary selector? (9 个回答) Ho
我正在尝试了解这个素数分解的特定解决方案(取自 http://rosettacode.org/wiki/Prime_decomposition#Python:_Using_floating_point
我知道这可能是一个愚蠢而简单的问题,但我对编程还很陌生。我有以下关于我在一个程序中看到的 if 运算符的问题。这是代码: d= -12.4; if(d) printf("%d \n", abs
我正在尝试制作一个脚本,根据天气情况输出用户名,他们被分配奇数或偶数值。我想我已经设法让奇数的工作,但偶数的不会输出。这是它的样子。 'commentid' 是确定将它们分配给奇数还是偶数的值。 ";
我的 NPE 的 Stacktrace 开始于: Caused by: java.lang.NullPointerException at pl.yourvision.crm.web.serv
我正在尝试查找给定数字(用户输入)是偶数还是奇数。 I'm simply applying AND operation on binary digits of a no. with 1, If the
有谁知道用于可变范围的桶的哈希函数(对于字符串,如果它重要的话),它总是奇数(或质数,如果需要的话)? 本质上,我正在寻找一个散列函数,它将在 n 个桶上提供均匀分布,其中 n 是奇数(或质数,因为
我是一名优秀的程序员,十分优秀!