How to vectorize the following code?

2 次查看(过去 30 天)
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

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-8-1
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 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by