Filtering for variable amount of constraints

Hi Everyone,
I have the following problem: I want to filter a dataset for a number of constraints. However, this number of constraints is variable.
I have the follwing code:
%% Filter for cargo constraints
%Solution 1
Data.VCsuit = Data.VC(strcmp(Data.Cargotypes{3,1},Data.VC{:,6})==1 | strcmp(Data.Cargotypes{2,1},Data.VC{:,6})==1,:);
%Solution 2
for i = 1 : height(Data.Cargotypes)
Data.VCsuit = Data.VC(strcmp(Data.Cargotypes{i,1},Data.VC{:,6})==1,:);
end
the problem with solution 1 is the variable, the problem of solution 2 is that it overwrites the previous filter. All datasets are tables. How can I best approach this? The dataset is in the attachements.

 Réponse acceptée

Fabian Leede
Fabian Leede le 16 Nov 2020
And some more trying fixed it. the final code for anyone in the future:
%% Filter for cargo constraints
Data.VCsuit = Data.VC(strcmp(Data.Cargotypes{2,1},Data.VC{:,6})==1,:);
for i = 3 : height(Data.Cargotypes)
temp = Data.VC(strcmp(Data.Cargotypes{i,1},Data.VC{:,6})==1,:);
Data.VCsuit = [Data.VCsuit;temp];
clear temp
end

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by