How to find dependent column vectors of a matrix for a given column vector?
조회 수: 3 (최근 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에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!