How to vectorize the following code?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mehmet OZC
le 1 Août 2016
Réponse apportée : Azzi Abdelmalek
le 1 Août 2016
function kod = sehir2kod(sehirName)
switch strtrim(sehirName)
case 'Adana'
kod = 01;
case 'Adıyaman'
kod = 02;
case 'Afyon'
kod = 03;
case 'Ağrı',
kod = 04;
case 'Amasya'
kod = 05;
end
sehirName = {'Ağrı';'Ağrı';'Ağrı';'Amasya';'Amasya';'Amasya';'Amasya';'Adana'};
kod = zeros(length(sehirName),1);
for idx = 1:length(sehirName)
kod(idx) = sehir2kod(char(sehirName(idx)));
end
Any help is appreciated. Thanks
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 1 Août 2016
v={'Adana','Adıyaman','Afyon','Ağrı','Amasya'}
sehirName = {'Ağrı';'Ağrı';'Ağrı';'Amasya';'Amasya';'Amasya';'Amasya';'Adana'};
[~,kod]=ismember(sehirName,v)
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!