How to find dependent column vectors of a matrix for a given column vector?
5 ビュー (過去 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
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
2016 年 3 月 21 日
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.
0 件のコメント
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!