Pulling data from a dialog box and putting the info into an if loop

6 views (last 30 days)
Trying to pull my input and run it through an if loop any ideas?
defineinput= {'A#'};
answer = inputdlg('Error code','Error Code Identifier',[1 75],defineinput);
userin={answer}
if userin=='A1'
disp('Engine Oil')
else
disp('fault code not recognized')
end

Accepted Answer

Adam Danz
Adam Danz on 25 Jul 2019
Edited: Adam Danz on 29 Jul 2019
1) no need to put the 'answer' result in another cell array (userin={answer})
2) use strcmp() or strcmpi() to compare strings instead of (userin=='A1')
3) There's no such thing as an 'if loop'. There are for-loops and while-loops and conditionals (if, else...)
defineinput= {'A#'};
answer = inputdlg('Error code','Error Code Identifier',[1 75],defineinput);
if strcmp(answer{:},'A1') % use strcmpi() for case insensitivity
disp('Engine Oil')
else
disp('fault code not recognized')
end

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!