matlab - 如何检查向量b是否在A列中?

标签 matlab

如何在matlab中判断b∈Col A还是b∉Col A? A 是 m x n 矩阵,其中 m >= n,b 是向量。是否已经有一个内置函数可以实现此目的,或者我需要创建一个函数吗?如果 b ∈ Col A,我将如何确定矩阵 A 是否具有正交列/是否正交?

最佳答案

您可以使用 ismember,如之前的答案中所述。

// some sample data
A = [eye(3); zeros(3)];
v = [0; 1; 0; 0; 1; 0];

ismember(A', v', 'rows')

要检查正交性,您可以执行以下操作

// A scalar initialised outside the for-loop. It stores sums of inner products.
dp = 0;

// Take the columns of A one by one and compute the inner product with all subsequent columns. If A is orthogonal, all the inner products have to be zero and, hence, their sum has to be zero.
for i = 1:size(A, 2)
    dp = dp + sum(A(:, i)'*A(:, i+1:end));
end

if (dp == 0)
    disp('The columns are orthogonal')
else
    disp('The columns are not orthogonal')
end

要拥有正交列,每列的范数必须为 1,因此:

// Check each column for unit length
M = mat2cell(A, size(A, 1), ones(size(A, 2), 1));

if find(cellfun(@(x)norm(x,2), M) ~= 1)
    disp('Columns are not of unit length')
else
    disp('Columns are of unit length')
end

请注意,如果 m=n(因为您允许这种情况),所有这些操作都会变得更简单、更快。

关于matlab - 如何检查向量b是否在A列中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23148476/

相关文章:

Pythonic 相当于 Matlab 的 textscan

matlab - 函数句柄内的逻辑短路

c - Matlab:调试C库,可能吗?

matlab - 在 Matlab 中绘制外轴

Matlab:按一定标准从矩阵中选择子矩阵

matlab - 将子文件夹中的文件添加到 sphinx 文档 (sphinxcontrib-matlabdomain)

matlab - 使用函数句柄创建函数和声明 syms 有什么区别?

matlab - 在matlab中更改dec2bin以获得逻辑向量

image - 如何在使用 refline 时阻止 MATLAB 调整图像大小或缩放图像

matlab - 如何在 Matlab 中绘制对角直方图