【发布时间】:2021-03-14 20:53:51
【问题描述】:
考虑任意函数:
function myFunc_ = myFunc(firstInput, secondInput)
myFunc_ = firstInput * secondInput;
end
现在想象一下,我想将上述函数映射到第一个输入 firstInput 的数组,而第二个输入 secondInput 是常量。例如,类似:
firstVariable = linspace(0., 1.);
plot(firstVariable, map(myFunc, [firstVariable , 0.1]))
其中0.1 是secondInput 的任意标量值,firstVariable 数组是firstInput 的任意数组。
我研究了arrayfun() 函数。但是,我不知道如何包含常量变量。另外,MATLAB 和 Octave 之间的语法似乎不同,或者我弄错了。拥有一个可以与同事共享的交叉兼容代码对我来说很重要。
【问题讨论】:
-
也许我误解了
map(fun, argv)的意思,但plot(firstVariable, myFunc(firstVariable, 0.1))不够吗? -
@Vicky
myFunc(firstVariable, 0.1))在 Octave 中返回一个标量。我不知道它在 MATLAB 上的作用! -
myFunc(firstVariable, 0.1)在 MATLAB 中返回一个向量!!如果在函数定义中用元素.*替换*会发生什么,这有什么不同吗? (octave.org/doc/v6.2.0/Broadcasting.html)