フィルターのクリア

How do I exclude data knowing the rownumbers?

1 回表示 (過去 30 日間)
Sam
Sam 2016 年 3 月 17 日
回答済み: Guillaume 2016 年 3 月 21 日
In parameter 'I' i have the rownumbers of the values i want to keep in a dataset. All the other rows have to be deleted. How do i do this?
[num,txt,raw] = xlsread('cg_uit_beta2');
A = txt(:,1);
[num2,txt2,raw2] = xlsread('cg_uit_beta2_2');
B = txt2(:,1);
L = ismember(A,B);
I = find(L); %this is a 1197 vector, containing the rownumbers of the values i want to keep.

回答 (2 件)

Guillaume
Guillaume 2016 年 3 月 21 日
find and your I array is not needed. You can directly use the logical array returned by ismember:
A(ismember(A, B)) = []; %remove elements in A that are not found in B
%or
C = A(ismember(A, B)); %copy elements of A that are found in B

Pavithra Ashok Kumar
Pavithra Ashok Kumar 2016 年 3 月 21 日
As per my understanding, l = array of indices that needs to be preserved and A is the complete matrix. If you have the list of rows you want to keep, use this way:
C = A;
C = C(l, :);
C would contain only the required indices. Hope this helps.

カテゴリ

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