Clear Filters
Clear Filters

strings in conditional statments

10 views (last 30 days)
ali altaif
ali altaif on 5 Oct 2022
Commented: ali altaif on 6 Oct 2022
Hello
I am trying to use a user input string 'yes' in a conditional statment. but can get it to work for me, any idea how can do this?
thanks in advance
% Taylor Series
syms a q w e r t y u i o p a s d f g h j k l z x c v b n m
y = input('Enter the exprestion to approximate: ');
a = input('Enter A symobol of the variable: ');
b = input('Enter At what: ');
c = input('Enter the number of terms: ');
TaylorSeries = taylor(y,a,b,'order', c) % taylor series expantion function
l = input('Do you want to plot: ');
if l == 'yes'
taylortool(TaylorSeries)
else
fprintf('alright')
end

Accepted Answer

Chunru
Chunru on 5 Oct 2022
l = input('Do you want to plot: ', "s"); % s for string
if l == "yes" % string comparison instead of char; 'yes'
taylortool(TaylorSeries)
else
fprintf('alright')
end

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!