filtering a cell array with date serial number

I have two cell arrays. Cell array one is a column that has a serial date number in every row and only one column. cell array two consists of many individual matrix tables which have a serial date number in column one whilst the other columns have other values. i want to filter cell array two in such a way that it only displays the rows in every individual matrix that contains the serial date number in cell array one.

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 9 月 27 日

0 投票

Under the assumption that you want to filter down to the entries that match any of the dates in the first matrix (instead of wanting to produce one set of matrices for the matches for the first entry, another set for the matches for the second set, and so on):
targetvals = cell2mat(CellArray1);
Subsets = cellfun(@(C) C(ismember(cell2mat(C),targetvals),:), CellArray2, 'Uniform', 0);

3 件のコメント

AA
AA 2015 年 10 月 1 日
ok it doesnt work because my question was wrong. I am not dealign with cell arrays but with matrices. So let me ask correctly again: MATRIX1 is a column that has a serial date number in every row and only one column. MATRIX2 has a a serial date number in column one whilst the other columns have other values. i want to filter MATRIX2 in such a way that it only displays the rows that correspond to the serial date number in the rows of MATRIX1.
Walter Roberson
Walter Roberson 2015 年 10 月 1 日
matches = ismember(MATRIX2(:,1), MATRIX1);
NewMATRIX2 = MATRIX2(matches,:);
AA
AA 2015 年 10 月 3 日
thanks i got one step closer. I want to collect the result in a cell array consisting of multiple matrices. I constructed this but i get the error message Cell contents assignment to a non-cell array object.
for x = 1:1
for y = 1:100
matches = ismember(a{1,y}(:,1), MATRIX1);
NewMATRIX2{y} = a{1,y}(matches,:);
end
end

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

カテゴリ

質問済み:

AA
2015 年 9 月 27 日

コメント済み:

AA
2015 年 10 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by