if else statement with strings
조회 수: 8 (최근 30일)
이전 댓글 표시
I want to take the user input and check if it is:
if the user input 'high pass' -> calcute this equation:GpRC = tf(R*C,1 + R*C);
if the user input 'low pass' --> calcute this equation:GpRC = tf(1,1 + R*C);
and then plot the true statement
this is the code:
%Make the user choose the filter
msgout = 'Choose from (high pass / low pass) \n';
%Calculate the gain
filter_option = input(msgout);
if strcmp(filter_option,'high pass')
GpRC = tf(R*C,1 + R*C);
plot(f_c,GpRC)
elseif strcmp(filter_option,'low pass')
GpRC = tf(1,1 + R*C);
plot(f_c,GpRC)
else
disp('Error!')
end
댓글 수: 3
채택된 답변
Riccardo Scorretti
2022년 5월 7일
That's being said, your problem is (most probably) that you wish to ask the user to enter a string:
filter_option = input(msgout);
In this case, you must add the second argument 's' to input, otherwise input will look for a numerical value or a numerical expression:
filter_option = input(msgout, 's'); % *** add 's' as second argument ***
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!