Trying to find cells of a matrix from vector values
이전 댓글 표시
I have 3 vectors
V1( 1; 3; 5;),
V2 (1; 3; 6;),
V3 (2; 3; 4; 5;) and i want to find in a matrix
A ( 1 5 2 4 3 1; 1 5 5 4 8 8; 5 2 4 6 3 10) at the respective row the 2 numbers closest to zero and return the number of the column. in my example it will be for the first row
V1 (1; 3;),
for the second V2 1; 3;),
and for the third V3 ( 2; 5;)
thank you
댓글 수: 4
Azzi Abdelmalek
2014년 6월 6일
This is not clear
napo
2014년 6월 6일
Azzi Abdelmalek
2014년 6월 6일
What are your data?, what is the expected result? and how to get this result?
napo
2014년 6월 6일
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2014년 6월 6일
편집: Andrei Bobrov
2014년 6월 6일
V={[1; 3; 5;];[1; 3; 6;];[2; 3; 4; 5;]};
A =[1 5 3 4 3 1; 1 5 5 4 8 8; 5 2 4 6 3 10];
n = numel(V);
out =zeros(n,2);
for jj = 1:n
B = A(jj,V{jj});
[~,ii] = sort(abs(B));
out(jj,:) = B(ii(1:2));
end
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!