matlab中vectorize,matlab – 使用arrayfun输出行的Vectorize函数,返回一个矩阵

我正在使用Octave,并且想要一个接受单个实数作为输入的函数,并输出一个固定长度的行向量.我知道arrayfun应该可以从它不清楚的文档中做到这一点.来自Octave 3.2中的help arrayfun:

If the parameter VAL after a further string input argument

“UniformOutput” is set ‘true’ (the default), then the named

function FUNC must return a single element which then will be

concatenated into the return value and is of type matrix.

Otherwise, if that parameter is set to `false’, then the outputs

are concatenated in a cell array.

[B1,…,Bm] = arrayfun(func,A1,…,An) calls the function specified by function handle func and passes elements from arrays A1,…,An, where n is the number of inputs to function func. Output arrays B1,…,Bm, where m is the number of outputs from function func, contain the combined outputs from the function calls. The ith iteration corresponds to the syntax [B1(i),…,Bm(i)] = func(A1{i},…,An{i}). The arrayfun function does not perform the calls to function func in a specific order.

看起来这在Matlab中有效,但在Octave中无效.我是否认为在Octave中无法使用arrayfun执行此泛化?是否有一些更聪明的方法来实现这一点,而不诉诸非流量化的循环?

作为参考,这是我的Octave结果:

octave:5> nums

nums =

@(c) ([c, c + 2, c + 4])

octave:6> arrayfun(nums,[1,2,3])

error: cellfun: expecting all values to be scalars for UniformOutput = true

error: called from:

error: /opt/local/share/octave/3.2.4/m/general/arrayfun.m at line 168, column 21

octave:6>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值