필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
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);

채택된 답변

Stephen23
Stephen23 2018년 12월 14일
편집: Stephen23 2018년 12월 14일
Use any:
if any(B(1,i)==65:90)
if ismember(B(1,i),65:90)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by