MATLAB: ¿What do I have to change when need to compare the value of a n position from a matrix with a variable type char

conditionalMATLABprogramming

Here is a a part of my script. Actually I am making a program that calculates the value in ohms from a resistor, so the user just have to type the colors. But I am having a problem with this: Error in calculadora_de_resistencias_electricas (line 8) if bandas([1,1])=='negro'*_
colores = input('Ingrese los colores de la resistencia eléctrica que desee calcular: ','s');
bandas = split (colores, " ");
disp(bandas);
%%PRIMERA BANDA DE LA RESISTENCIA
if bandas(1,1)=='negro'
bandas(1,1) = 0;
end
if bandas(1,1)=='cafe'
bandas(1,1) = 1;
end
if bandas(1,1)=='rojo'
bandas(1,1) = 2;
end
if bandas (1,1)=='naranja'
bandas(1,1) = 3;
end
if bandas(1,1)=='amarillo'
bandas(1,1) = 4;
end
if bandas(1,1)=='verde'
bandas(1,1) = 5;
end
if bandas (1,1)=='azul'
bandas(1,1) = 6;
end
if bandas(1,1)=='violeta'
bandas(1,1) = 7;
end
if bandas(1,1)=='morado'
bandas(1,1) = 7;
end
if bandas (1,1)=='gris'
bandas(1,1) = 8;
end
if bandas(1,1)=='blanco'
bandas(1,1) = 9;
end

Best Answer

Let me suggest a different approach:
% Input color
colores = input('Ingrese los colores de la resistencia eléctrica que desee calcular: ','s');
% Specify colors and resistances
col={'negro','cafe','rogo','naranja'}
res=[0 1 2 3];
% Compare strings and find resistance
res(strcmp(colores,col)) %
Note that I am lazy and did not add all colors myself.