フィルターのクリア

Trying to find cells of a matrix from vector values

1 回表示 (過去 30 日間)
napo
napo 2014 年 6 月 6 日
コメント済み: napo 2014 年 6 月 6 日
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
Azzi Abdelmalek 2014 年 6 月 6 日
What are your data?, what is the expected result? and how to get this result?
napo
napo 2014 年 6 月 6 日
my data are the vectors (V1( 1; 3; 5;),V2 (1; 3; 6;), V3 (2; 3; 4; 5;) ) and the matrix A ( 1 5 3 4 3 1; 1 5 5 4 8 8; 5 2 4 6 3 10), the expected result is V'1 (1; 3;),
V'2 1; 3;),
V'3 ( 2; 5;) and the way to get this is by going to the first row of A (1 5 2 4 3 1) check the columns from V1 values (1 3 5 ) find the two values that is closest to zero, for column 1 A (1,1)= 1 , for 3 A(1,3) = 2 , for 5 A (1,5)=3 and create a new vector V'1 (1,3)

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 6 月 6 日
V1=[ 1; 3; 5]'
V2=[1; 3; 6]'
V3 =[2; 3; 4; 5]'
A =[ 1 5 3 4 3 1; 1 5 5 4 8 8; 5 2 4 6 3 10]
v={V1,V2,V3}
for k=1:size(A,1)
[ii,jj]=sort(A(k,v{k}));
out(k,1:2)=v{k}(jj(1:2));
end
disp(out)

その他の回答 (1 件)

Andrei Bobrov
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
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2014 年 6 月 6 日
corrected
napo
napo 2014 年 6 月 6 日
this works but returns the values inside the cells and i want the number of the column that the cell is.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by