MATLAB: How to compare string

if statementstring

i want to take input fuel=CH4 or CO or Co2, %its num + string input if fuel==CH4 % if fuel is CH4 i need to fix some value for variable %if fuel is Co or Co2 i need to fix some value can you please help me how to do it?

Best Answer

Try this:
fuel=input('select the gaseous component CH4,ethane,propane,butane,H2,CO,CO2,N2\n');
if prod(ismember(fuel,'CH4'))
density=0.716; %kg/m^
LCV=35.83; %MJ/m^3
cc=1; hh=4; oo=0; nn=0;
TMmass=cc+hh+oo+hh;
disp('total mass of CH4');
disp(TMmass);
end
if prod(ismember(fuel,'ethane'))
density=1.342; %kg/m^3
disp(density);
LCV=63.76; %MJ/m^3
disp(LCV);
cc=2;
disp(cc);
hh=6;
disp(hh);
oo=0;
disp(oo);
nn=0;
disp(nn);
TMmass=cc+hh+oo+hh;
disp('total mass of CH4');
disp(TMmass);
end
Do not forget to enter your input in char form. Like
>>'CH4'
or
>>'ethane'