Logical Operator with cell

2 次查看(过去 30 天)
Giorgio Gardella
Giorgio Gardella 2019-1-27
回答: Voss 2023-12-14
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)))];

回答(1 个)

Voss
Voss 2023-12-14
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

类别

Help CenterFile Exchange 中查找有关 Encryption / Cryptography 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by