Filter löschen
Filter löschen

filtering a cell array according to a matrix

1 Ansicht (letzte 30 Tage)
AA
AA am 8 Okt. 2015
Kommentiert: Star Strider am 8 Okt. 2015
Imagine these two variables 'a' and 'b'. I want to filter the matrices in cell array 'b'. The matrices in cell array 'b' have 7 columns. The rows of every number in column 5 to 7 of the matrices in cell array 'b' that match the numbers in matrix 'a' should be recorded in a new variable c with the only exception that column 5 to 7 are deleted and only column 1 to 4 are recorded. How can I put a code for this?
a=rand(18,1)
b={rand(1877958,7); rand(1251972,7)};

Akzeptierte Antwort

Star Strider
Star Strider am 8 Okt. 2015
Random numbers are, well, random, so there is no match (using rand), and I can only say that this code runs. I will leave it to you to test it in your actual application:
a=rand(18,1);
b={rand(1877958,7); rand(1251972,7)};
db = cell2mat(b); % Double Matrices Are Easier To Work With
b57 = db(:,5:7);
Lia = ismember(b57,a);
idx = find(sum(Lia,2)); % Row Indices Of ‘b’ Where ‘b57’ & ‘a’ Match
c = db(idx,1:4) % Desired Output (As I Read The Question)
  2 Kommentare
AA
AA am 8 Okt. 2015
thanks, it worked. i modified it a bit
for x = 1:100
for y = 1:61
Lia = ismember(dateshalf{x,y},ans);
idx = find(sum(Lia,2)); % Row Indices Of ‘b’ Where ‘b57’ & ‘a’ Match
Liaa{x,y}=idx;
qq{x,y} = q{x,y}(Liaa{x,y},1:60); % Desired Output (As I Read The Question)
end
end
Star Strider
Star Strider am 8 Okt. 2015
My pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by