Borrar filtros
Borrar filtros

Is it possible to make an if-statement with multiple conditions (a vector of numbers)?

4 visualizaciones (últimos 30 días)
Is it possible to make an if-statement with multiple conditions? I want the value of B(1, i) to change if it's any of the numbers 65 to 90. It does not work to simply type "if B(1, i)==65:90".
%Text that I want to decrypt
A=['VYDQBBO OEK CQDQWUT JE TUSHOFJ JXYI JUNJ!'];
B=double(A);
l=length(B);
x=(65:90);
%Loop to roll every letter 10 steps forward in the alpabet
for i=1:l
if (B(1, i)==x)
B(1, i)=(B(1, i)+10);
disp(B(1, i));
if (B(1, i)>90)
B(1, i)=B(1, i)-26;
end
end
end
A2=char(B);
disp(A2);

Respuesta aceptada

Stephen23
Stephen23 el 14 de Dic. de 2018
Editada: Stephen23 el 14 de Dic. de 2018
Use any:
if any(B(1,i)==65:90)
if ismember(B(1,i),65:90)

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by