Show column which starts with certain numbers

3 ビュー (過去 30 日間)
Jakub
Jakub 2013 年 4 月 12 日
Hi, i have matrix size 500x500. And i need to find column which starts with vector [1 2]'. Only one column in whole matrix starts with these two certains numbers. The matrix looks something like this
[1 1 1 1 1]
[1 2 3 4 5]
[1 2 3 4 5]
I need function that tells me column number two starts with 1 and second value is 2.
Thanks for help!

採用された回答

Cedric
Cedric 2013 年 4 月 12 日
If your matrix is named M, you can do
col = M(1,:) == 1 & M(2,:) == 2 ;
to get a vector of logicals indicating the relevant column, and
find(col)
to get the column number.

その他の回答 (1 件)

Youssef  Khmou
Youssef Khmou 2013 年 4 月 12 日
編集済み: Youssef Khmou 2013 年 4 月 12 日
hi, try :
a=rand(500);
a(1:2,312)=[1 2]; % for example the column 312 starts with [1 2]
b=a(1:2,:);
test=[1 2]';
for n=1:length(b)
diff(n)=norm(b(:,n)-test);
end
Index=find(diff==0);
Index is the number of the column,

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by