问题标签 [bsxfun]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
5334 浏览

matlab - Matlab错误:两个输入数组的非单一维度必须相互匹配

我有一个 1000x1 数组,我希望它根据 lambda 值 lam_packet 分成相等的部分,然后在每个部分中,我将用随机二进制值替换 0 0 0 0 ,但是当我调用这个函数时,我得到一个错误

请任何帮助将不胜感激。

0 投票
1 回答
1024 浏览

matlab - bsxfun 可用于稀疏矩阵吗

我想将逐个元素的二元运算应用于大型逻辑向量。这些向量的内容是错误的,因此出于性能考虑,最好使用稀疏矩阵。如果我这样做,则生成的矩阵不正确。

示例

在这种情况下 C 是

如果我使用稀疏矩阵 C 是

这显然是错误的。

我监督了什么还是这是一个 Matlab 错误。

0 投票
5 回答
1009 浏览

matlab - 如何在 Matlab 中加快对分位数的调用?

我有一个带有一个相当明显瓶颈的 MATLAB 例程。我已经对函数进行了概要分析,结果在函数中使用了 2/3 的计算时间levels

在此处输入图像描述

该函数levels接受一个浮点矩阵并将每一列拆分为nLevels桶,返回一个与输入大小相同的矩阵,每个条目都替换为其所属桶的编号。

为此,我使用quantile函数来获取存储桶限制,并使用循环将条目分配给存储桶。这是我的实现:

我能做些什么来加快速度吗?代码可以向量化吗?

0 投票
2 回答
15430 浏览

python - Is there an equivalent to the MATLAB function bsxfun in python?

I'm trying to port some of my code from matlab to python, and some of it uses the bsxfun() function for virtual replication followed by multiplication or division (I also use it for logical operations). I'd like to be able to do this without actually replicating the vector (either with a function or with some kind of diagonal matrix) before multiplying or dividing to save on memory and time.

If there's an equivalent of bsxfun in a C library of some kind, that would of course also work.

0 投票
1 回答
8517 浏览

matlab - Least squares circle fitting using MATLAB Optimization Toolbox

I am trying to implement least squares circle fitting following this paper (sorry I can't publish it). The paper states, that we could fit a circle, by calculating the geometric error as the euclidean distance (Xi'') between a specific point (Xi) and the corresponding point on the circle (Xi'). We have three parametres: Xc (a vector of coordinates the center of circle), and R (radius).

Circle fitting Equations

I came up with the following MATLAB code (note that I am trying to fit circles, not spheres as it is indicated on the images):

The fitting however is not too good: if I start with the good parameter vector the algorithm terminates at the first step (so there is a local minima where it should be), but if I perturb the starting point (with a noiseless circle) the fitting stops with very large errors. I am sure that I've overlooked something in my implementation.

0 投票
1 回答
1401 浏览

c++ - C++ Armadillo:- Equivalent to Matlab's bsxfun

Does Aramadillo have a general purpose equivalent to matlab's bsxfun, which performs element wise operations e.g bsxfun(@minus,A,B)? I have seen that Armadillo does have element wise multiplication and division, but no indication that a generalized function is available.

0 投票
1 回答
925 浏览

matlab - 单例展开的二元运算——标量输出

有 bsxfun 之类的功能:http: //www.mathworks.com/help/techdoc/ref/bsxfun.html但是它在逐个元素模式下工作。我想要在逐个向量模式下(以及标量输出)工作的类似函数。

作为说明,我会尝试以这种方式在这里使用 bsxfun。作为内部函数,我将使用(这只是一个示例)向量的点积。

上面的虚拟函数foo需要 2 个向量,结果是标量。每次调用它时,我们都会看到一条消息。

结果是:

所以,两个调用(很好),但是我们得到了一个矩阵,而不是一个向量(一对 2 个标量)。可以说,在这种情况下只获得第一行就足够了,因为矩阵是由 bsxfun 预先创建的,其余的将始终为零。

但情况并非总是如此——有时我得到了一些实际值,而不仅仅是零——而且恐怕会涉及到一些副作用(上面的点积是最简单的例子)。

问题

那么,是否有一个类似于 bsxfun 的函数,但它获取向量并期望每个向量的每个操作都有一个标量?

0 投票
1 回答
567 浏览

matlab - Create third matrix in MATLAB from combination of two other matrices

I have two expressions in MATLAB that represent a 365x24 matrix. The first expression has 10, 365x24 matrices and is therefore

and the second expression which is again 365x24 but with three possible matrices therefore is

Now, I am looking to create a third matrix that adds the elements in the same position above and thus form a 365x24 matrix. However I want a set of matrix with all possible combinations of the two expressions shown above (therefore this matrix must be 365x24x30.

How do I go about this? What about the bsxfun function in MATLAB?

0 投票
2 回答
522 浏览

matlab - 带有 bsxfun 的用于结束循环的 matlab 复合体

我有一个doubles 的 2092x252 矩阵,需要创建一个for使用bsxfun. 让我们只说这个例子bsxfun(@minus)。我需要循环完成的是bsxfun(@minus)使用每一列作为索引来运行。例如,将第 1 列指定为索引会得到bsxfun(@minus)与第 2:252 列的差异(使用 )。然后将第 2 列设置为索引并获得与第 3:252 列的差异(再次使用bsxfun(@minus))。循环必须继续运行直到bsxfun(@minus, 251, 252)

输出将是一个变量而不是 251 个变量。总共将有 31626 个数据点。

另外,请您解释一下代码。

0 投票
1 回答
944 浏览

multithreading - matlab bsxfun不是多线程?

我正在使用 Matlab R2011a,根据文档,该bsxfun函数自 R2009a (http://www.mathworks.com/help/techdoc/rn/br5k34y-1.html)以来是多线程的。但是,当我使用 bsxfun 将矩阵与这样的上限和下限进行比较时:

在任务管理器上我看到的不是只有一个核心被占用。我错过了什么还是这是正常的?