You can use the strcmp()
function in MATLAB to compare strings. Here's how you can make an if statement that checks if a string says "on":
main.m135 chars8 lines
In the above code, strcmp(inputString, 'on')
compares the values of inputString
and 'on'
. If they are the same, it will return true
, and the first statement will be executed. Otherwise, if they are different, it will return false
, and the second statement will be executed.
You can replace the disp()
statements inside the if-else block with any other code that you want to execute based on the string comparison condition.
gistlibby LogSnag