Logical Operator with cell

2 vues (au cours des 30 derniers jours)
Giorgio Gardella
Giorgio Gardella le 27 Jan 2019
Réponse apportée : Voss le 14 Déc 2023
I have done this code and I would like to enshorten it. Do you have a suggestion?
Indexn = strfind(reg_freight_train(:,3),'ITC');
c = find(not(cellfun('isempty',Indexn)));
reg_train_LD_ita =reg_freight_train(c,:);
LOAD=str2double(reg_train_LD_ita(:,5:size(reg_train_LD_ita,2)));
Indexn = strfind(reg_freight_train(:,3),'ITD');
c = find(not(cellfun('isempty',Indexn)));
reg_train_LD_ita =reg_freight_train(c,:);
LOAD=[LOAD ; str2double(reg_train_LD_ita(:,5:size(reg_train_LD_ita,2)))];
Indexn = strfind(reg_freight_train(:,3),'ITH');
c = find(not(cellfun('isempty',Indexn)));
reg_train_LD_ita =reg_freight_train(c,:);
LOAD=[LOAD ; str2double(reg_train_LD_ita(:,5:size(reg_train_LD_ita,2)))];

Réponses (1)

Voss
Voss le 14 Déc 2023
names = {'ITC','ITD','ITH'};
LOAD = [];
for ii = 1:numel(names)
LOAD = [LOAD; str2double(reg_freight_train(contains(reg_freight_train(:,3),names{ii}),5:end))];
end

Catégories

En savoir plus sur Encryption / Cryptography dans Help Center 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