我正在尝试“自动”生成向量 0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30
(在乘法空间中)。
我知道 linspace 和 logspace 函数,但我找不到任何类似的乘法空间函数。
有吗?否则,如何生成我需要的向量?
最佳答案
使用 bsxfun
的简单方法,还考虑乘法到更小的空间:
x = [0.01,0.03,0.05] % initial vector, works for various lengths
n = 12; % times it should get multiplied in rising direction
m = 3; % times it should get multiplied in falling direction
Z = bsxfun( @times, x(:), 10.^(-m:n) )
Z = Z(:)
% if preferred, bulky one-liner:
% Z = reshape( bsxfun( @times, x(:), 10.^(-m:n) ) , 1 , [])
我假设与乘法向量相乘,例如:
10.^(0:n) = 1 10 100 1000 10000 100000 ....
但自定义向量 Y
也是可能的:
Z = bsxfun( @times, x(:), Y(:)' ) Z = Z(:)
关于arrays - 如何在 Matlab 中生成乘法空间向量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21059333/