How to vectorize the following code?

2 visualizaciones (últimos 30 días)
Mehmet OZC
Mehmet OZC el 1 de Ag. de 2016
Respondida: Azzi Abdelmalek el 1 de Ag. de 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

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 1 de Ag. de 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)

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by