How to find dependent column vectors of a matrix for a given column vector?

2 次查看(过去 30 天)
For example if I have a matrix m where:
m=[1 2 3 4; ...
1 5 3 6; ...
1 7 3 8];
if I put as an input column 1 ,m(:,1), I receive the result:
r=[3 3 3]'
thanks,
  1 个评论
Image Analyst
Image Analyst 2016-3-17
编辑:Image Analyst 2016-3-17
I don't understand. If you pass some function column 1 of m, which is [1;1;1], then how are you getting the result of [3,3,3]'??? Does it have something to do with m having 3 rows? So the function I would guess would recognize that [1;1;1] is column 1, and would get, say, foundColumnNumber = 1 (because it found it in column #1), but then do you do something like
r = m(1, foundColumnNumber) * ones(size(m, 1), 1);
where it takes the first element in the found column and replicates it for as many rows as you have???

请先登录,再进行评论。

回答(2 个)

Pavithra Ashok Kumar
One of the ways to find this would be to do an element-wise ratio and check if the multiple is constant. The same can also be achieved by using the cross product of the vectors.
for i = 1:ncols
b = A(:,i)./X; %Do element-wise division
if((b(1)*ones(nrows,1)) == b) % check if it is a constant
disp(i); % This would give the indices of the dependent columns
end
end
However, If you could give more information on the use-case, the community might be able to suggest better alternatives. Hope this helps.

Stephen23
Stephen23 2016-3-21
Guessing a bit because the question is not totally clear... here is a function that returns the column indices of any columns that are integer multiples of the input column vector:
>> m = [1,2,3,4;1,5,3,6;1,7,3,8];
>> fun = @(c)all(~diff(bsxfun(@rdivide,m,c)));ú
>> fun([1;1;1])
ans =
1 0 1 0
>> fun([2;3;4])
ans =
0 0 0 1
>> fun([2;5;7])
ans =
0 1 0 0
And you can extract those columns by using these indices:
>> m(:,fun([2;3;4]))
ans =
4
6
8
>> m(:,fun([1;1;1]))
ans =
1 3
1 3
1 3

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by